56

How do I reset my local git repo to be exactly the same as the remote repo?

I've tried:

git reset --hard HEAD^

But now git status says I have diverging commits. I basically want to just wipe anything I've got locally and get the exact remote repo on my local machine.

James
  • 106,638
  • 30
  • 159
  • 173
  • 1
    possible duplicate of [How to reset my local repository to be just like the remote repository HEAD](http://stackoverflow.com/questions/1628088/how-to-reset-my-local-repository-to-be-just-like-the-remote-repository-head) – CharlesB Apr 16 '12 at 07:34
  • Does this answer your question? [Reset local repository branch to be just like remote repository HEAD](https://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head) – Kay V Mar 08 '21 at 03:28

2 Answers2

122

git reset --hard HEAD^ will only reset your working copy to the previous (parent) commit. Instead, you want to run

git reset --hard origin/master

Assuming remote is origin and the branch you want to reset to is master

CharlesB
  • 80,832
  • 27
  • 184
  • 208
  • 1
    in my case I also need to run "git pull" to point my local master correctly. otherwhise my local would stay in detached mode – yigal Dec 29 '20 at 18:47
  • 1
    If you want to remove local untracked files, you can run `git clean` first. Run `git clean -n` to see what would happen (i.e. which files would be removed), and `git clean -f` to actually remove them. – f.k May 02 '21 at 14:23
  • This will only reset the given branch. Not the full repo as was asked by OP. Just to be aware. – Ivan Balashov Dec 27 '21 at 08:09
15

You could delete the current branch, and create the branch again at the remote/branchname commit

git branch -D branchname
git checkout remote/branchname
git branch branchname
Sailesh
  • 24,387
  • 4
  • 31
  • 47