top | item 2874968

Git: fetch and merge, don’t pull

101 points| eplanit | 14 years ago |longair.net | reply

20 comments

order
[+] justin_vanw|14 years ago|reply
I don't quite follow what he is trying to say.

From the manpage for git pull: git-pull - Fetch from and merge with another repository or a local branch

Git pull is identical to git fetch && git merge $remote_branch. He's saying that it prevents you from learning how branching works. So, if he were explicit, he should say 'Don't use git until you know how branching works at some level.', which is good advice. Not using git pull is a pretty sensational way to get at that nugget.

[+] masklinn|14 years ago|reply
His issues seem to be mostly:

* If you `git pull`, you don't get the chance to diff between your local branch and what you just fetched and check if you really want to do that merge, using `git fetch` and `git merge` makes it more likely you'll do that check

* Getting used to `git fetch` means if you need to diverge from the straight `git fetch; git merge` workflow (because you want to rebase, or you have a high number of active topic branches floating around) you're already halfway there.

[+] viraptor|14 years ago|reply
Very nice description of a number of use cases. I was just a bit annoyed that the title was described in a very hand-waving way (do it because it's more useful sometimes). With so many other examples I really expected a detailed description of some situation where fetch/pull makes a huge difference.
[+] natesm|14 years ago|reply
No mention of "git pull --rebase"?
[+] stock_toaster|14 years ago|reply
I like it so much, I even have `autosetuprebase = remote` in my gitconfig.
[+] yason|14 years ago|reply
Not sure if it warrants an article but I've never found any use for git-pull either. When I want to fetch and merge/rebase, I can do just that; I never figured why would I want to use git-pull for it. But on the other hand, I've only used git for about five years and I've only learned the most important low-level commands yet.
[+] adamjernst|14 years ago|reply
This is one of the things that Mercurial got right. (In Mercurial, you pull and then merge separately, usually.)
[+] anandpdoshi|14 years ago|reply
git is deep. And you can do the same thing using different steps and different number of steps. I think this post provided a good tip on how to go about merging remote changes into your local. If one finds that git pull requires a lot of cleanup activity, git fetch and git merge is a good way to go..
[+] ZoFreX|14 years ago|reply
Interesting to learn. In Mercurial (which is what I use primarily) pull does not merge unless you ask it to. Is there a list anywhere of gotchas in git for people coming from other DVCS? (i.e. things like commands with the same name that do subtly different things, such as this)
[+] masklinn|14 years ago|reply
> In Mercurial (which is what I use primarily) pull does not merge unless you ask it to.

Actually, in Mercurial `pull` does not ever merge. It can update if you ask it to (with `-u`), but it won't merge.

`hg fetch` (standard extension) can merge (it's basically "pull and update, if update fails merge"), but it might go the way of the dodo pretty soon[0]

[0] http://www.selenic.com/pipermail/mercurial-devel/2011-August...

[+] dexen|14 years ago|reply
Regretable case of different name for same functionality. May indeed be misleading if you switch back-and-forth between SCMs.

hg pull == git fetch

git pull == { hg pull; hg merge; }

[+] mise|14 years ago|reply
The article mentions:

    $ git fetch
    $ git checkout master
    $ git merge origin/master
On the third (last) line of code above, is there a more short-hand way to say "merge the remote tracked branch related to this current branch"?
[+] DrJ|14 years ago|reply
git pull?
[+] freedrull|14 years ago|reply
Git pull is nice, but it is good to know what's going on underneath the hood.