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?
Asked
Active
Viewed 1.8e+01k times
2 Answers
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