> ## Content Index
> Fetch the complete content index at: https://www.binarysludge.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Recovering from a forced push to a tracked repository
- URL: https://www.binarysludge.com/2013/03/26/grep-git-commits-for-a-certain-word/
- Published: 2013-03-26T14:40:00.000Z
- Updated: 2013-03-26T14:47:04.000Z
- Author: Andrew Martin
- Tags: bash, Programming, git, #Import 2026-10-22 12:56

If a remote repository has been force updated (`git push -f`), the local repository's history must be rewritten to account for it (unless the master is incorrect, in which case a forced update may be the only corrective measure).

A [reset](https://www.kernel.org/pub/software/scm/git/docs/git-reset.html?ref=binarysludge.com "git reset") with the `--hard` flag will

> reset the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded

A fetch is necessary first to ensure the remote changes are reflected in the local indexes.

To reset the local repository's HEAD to the remote's HEAD:

$ git fetch
$ git reset --hard origin/master