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?
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.
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.
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.
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.
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.
$ 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With