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.

2
  • 2
    FYI git pull --rebase does a fetch followed by a rebase
    – opqdonut
    Aug 15, 2012 at 11:47
  • Actually I am asking the advantage from the github/OSS context, not only the differences,
    – Ryan
    Aug 15, 2012 at 16:21

1 Answer 1

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.

3
  • Whoops, answered before I saw the duplicate. That shouldn't be surprising. Aug 15, 2012 at 12:27
  • 2
    Thanks, git pull --rebase is help a lot
    – cakyus
    Apr 20, 2017 at 7: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 4, 2023 at 15:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.