What is the difference between git pull and git reset --hard origin/<branch>?

technophyle picture technophyle · Mar 27, 2017 · Viewed 7.8k times · Source

I find the latter to be faster than the first, so I usually do that after git fetch whenever I need to sync my local branch with the remote. What is the difference if any at all?

Answer

Penguin Brian picture Penguin Brian · Mar 27, 2017

The following commands:

git fetch
git reset --hard origin/<branch>

will discard all local changes.

Where as:

git pull

Which is exactly the same as:

git fetch
git merge origin/<branch>

will attempt to preserve local changes.