40

I have a local git repository, but things get wrong and complicated and I simply want to overwrite all the files in my local directory with the latest version of what is on the remote repository. This would be like a clone, but for an already setup local git repository.

For example: if use git pull, then I don't get locally deleted folders back from the remote.

Is it checkout that I must use? But how to tell it to retrieve the files from a remote (and not from the stage) and overwrite all?

Charles
  • 50,943
  • 13
  • 104
  • 142
user1738984
  • 584
  • 1
  • 5
  • 15
  • Take a look: http://stackoverflow.com/questions/6284809/how-to-pull-from-remote-git-repository-and-override-the-changes-in-my-local-repo – vfcosta Oct 11 '12 at 17:48
  • 2
    Thank you ! To the person who downvoted my question : I did a long search before (not only on Stackoverflow), but did not found this answer. And for some reason the first line of my question got deleted after I edited it (I can't even add a "Hi, ", it gets deleted o_O) – user1738984 Oct 11 '12 at 18:05

1 Answers1

67

You probably want to use git reset. Assuming you have done a git fetch recently, the following will discard everything in your local and reset it to the point you specify as the final argument (in this case the current HEAD of the origin/master remote tracking branch):

$ git reset --hard origin/master
Brian Phillips
  • 12,693
  • 3
  • 29
  • 26
  • 2
    If there are no commits in local master, Just `git checkout master` should work – balki Oct 12 '12 at 13:43
  • 7
    No, checking out master will not work if you are already on master. The files remain changed. You need to git reset --hard origin/master – Steve Swinsburg Jun 06 '13 at 13:14