Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 904
technophyle Avatar asked Mar 27 '17 03:03

technophyle


People also ask

What is the difference between git pull and git pull origin?

Remember, a pull is a fetch and a merge. git pull origin master fetches commits from the master branch of the origin remote (into the local origin/master branch), and then it merges origin/master into the branch you currently have checked out.

What does git reset -- hard origin branch do?

git reset --hard origin/master works only as a full wipe out if you are in a local branch. If you are in the master branch instead, and if you have made changes, you can only drop all of the files that you made or changed.

What is the difference between git reset and git reset -- hard?

git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory. Only use this if you know what you're doing.

Does git reset pull?

You can use the git reset command to undo a git pull operation. The git reset command resets your repository to a particular point in its history. If you made changes to files before running git pull that you did not commit, those changes will be gone.


2 Answers

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.

like image 94
Penguin Brian Avatar answered Sep 21 '22 06:09

Penguin Brian


$ git pull                         # takes the latest changes of origin/branch (exists both local & remote changes)  $ git reset --hard origin/branch   # replace your local with origin's branch history (discard local changes) 

Example: Say, we have two commits in local A, B and remote has two commits A, C. Now if you pull then your local contains A, B, C unlike if reset then your local will have A, C not B.

like image 25
Sajib Khan Avatar answered Sep 22 '22 06:09

Sajib Khan