212

I need to throw away all the changes in my local repository and pull all the code from the remote repository. What is the Git command to do this?

honk
  • 9,137
  • 11
  • 75
  • 83
Barka
  • 8,764
  • 15
  • 64
  • 91

2 Answers2

436

Provided that the remote repository is origin, and that you're interested in master:

git fetch origin
git reset --hard origin/master

This tells it to fetch the commits from the remote repository, and position your working copy to the tip of its master branch.

All your local commits not common to the remote will be gone.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
13

As an addendum, if you want to reapply your changes on top of the remote, you can also try:

git pull --rebase origin master

If you then want to undo some of your changes (but perhaps not all of them) you can use:

git reset SHA_HASH

Then do some adjustment and recommit.

sebastian-c
  • 15,057
  • 3
  • 47
  • 93