6

Possible Duplicate:
git pull VS git fetch git rebase

I see some git project recommended you to update the project via

git fetch; git rebase origin master

Are there any advantages in doing this, as compare to

git pull

from the perspective of opensource projects on github, since you always trust the remote anyway.

Community
  • 1
  • 1
Ryan
  • 10,041
  • 27
  • 91
  • 156

1 Answers1

10

If you haven't made any changes to your local copy of the branch, the two sets of commands will result in exactly the same history. The difference comes into play when you have made local commits to your current copy of the branch.

If you do git pull any changes made on the remote will be merged into your local branch and you'll have a merge commit in the history. On the other hand, if you do a fetch followed by a rebase (or git pull --rebase) your local changes will be replayed on top of the remote changes. This results in a cleaner history since you'll have less merge commits cluttering the history.

It also often makes your changes easier to merge upstream since the history before your new commits matches the history on the remote.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113
  • Whoops, answered before I saw the duplicate. That shouldn't be surprising. – Michael Mior Aug 15 '12 at 12:27
  • 2
    Thanks, `git pull --rebase` is help a lot – cakyus Apr 20 '17 at 07:31
  • Why did I, after all these years, first find out about `git pull --rebase` today. All these years I have bee fetching and rebasing manually, putting the arguments in the wrong order half the time. Thank you good sir! ️ – Graunephar Jul 04 '23 at 15:11