[git] How can I pull from remote Git repository and override the changes in my local repository?

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?

This question is related to git

The answer is


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.


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.