116

I'm starting to play with Git now and I'm a little bit confused. For me, looks like there are a lot of options to do the same thing. My question for now is what is the difference between the commands below:

  • git remote update
  • git fetch
  • git pull

Also which one is more applicable for update a local copy of a remote branch?

Davi Garcia
  • 1,294
  • 2
  • 9
  • 11
  • 2
    See [Differences between git remote update and fetch?](http://stackoverflow.com/questions/1856499/differences-between-git-remote-update-and-fetch), and also [What is the difference between `git fetch origin` and `git remote update origin`?](http://stackoverflow.com/questions/2688251/what-is-the-difference-between-git-fetch-origin-and-git-remote-update-origin). –  Jul 18 '13 at 01:28
  • Possible duplicate of [What's the difference between 'git pull' and 'git fetch'?](http://stackoverflow.com/questions/292357/whats-the-difference-between-git-pull-and-git-fetch). –  Jul 18 '13 at 02:12

2 Answers2

130

git remote update will update all of your branches set to track remote ones, but not merge any changes in.

git fetch will update only the branch you're on, but not merge any changes in.

git pull will update and merge any remote changes of the current branch you're on. This would be the one you use to update a local branch.

Makoto
  • 104,088
  • 27
  • 192
  • 230
  • 10
    `git fetch` will update other branches, if you want. Try `git fetch --all` – Arafangion Jul 18 '13 at 00:35
  • 8
    Did you know you can actually do fast-forward merges with fetch by using refspecs?: `git fetch origin master:master`. That only works if you don't have `master` checked out though, because Git has to move the branch pointer and won't do it if you're currently on the branch. –  Jul 18 '13 at 01:31
  • 12
    'get fetch' seems to fetch all branches when I do it, even without using the --all switch.(Git for windows 2.10.0.1) – Simon P Stevens Sep 06 '16 at 13:56
  • @ColinDBennett: That was a ***significant*** change to an older post. If you feel like an answer warrants that much detail, it'd be better for you to post your own answer. – Makoto Oct 12 '16 at 22:06
  • 30
    This answer has several errors. Mostly they come from confusing the *remote tracking branches* with regular branches, which is a big mistake. `git fetch` does not update the "branch you're on". But it does update all remote tracking branches for the remote `origin` or whatever remote the upstream tracking branch for the current remote is. – Colin D Bennett Oct 12 '16 at 22:08
  • 30
    Also see the VERY complete answer in http://stackoverflow.com/a/17512004/994153 which describes how `git fetch --all` didn't exist at one time, so `git remote update` what more useful. Now that `--all` has been added to `git fetch`, `git remote update` is not really necessary. – Colin D Bennett Oct 12 '16 at 22:09
  • 5
    `git fetch --all` does not fetch all branches; it fetches from all remotes. – Felipe Alvarez Jul 01 '17 at 04:15
  • I have a project with several sub-modules. Did a git clone, then git submodule init step. Everthing was fine, able to build, no problems. Now, I want to update *everything* to latest HEAD, so I "git pull". I see git accessing submodules. But "git status" shows some submodules modified (New Commits), I didn't modify anything in those. I change into those directories, and do a git pull, I see a "HEAD detached". How does that make sense ? Why would the head be detached ? (git == overcomplicated !) What is the command to pull *everything* (make me fully up to date )? – SmittyBoy Feb 18 '20 at 10:31
  • `git fetch` support concurrent updates (`-j/--jobs`), `git remote update` does not. – akim Nov 07 '20 at 14:36
  • The `git remote update` command is used to fetch updates from all of your remotes, NOT branches. – f.ashouri Jul 20 '23 at 22:58
-7

Not sure about the git remote update, but git pull is the git fetch followed automatically by a git merge...

This is partially a duplicate. Check: What is the difference between 'git pull' and 'git fetch'?

Also, if it means anything to you, I've never used git remote update neither fgit fetch. You can do just fine with pull, commit and push.

Hope it helps..

Community
  • 1
  • 1
LucasA
  • 192
  • 1
  • 9
  • 1
    `git fetch` has its place...sometimes you only care about how many branches your manager has pruned; sometimes you only want the updates from the branch you're on. – Makoto Jul 18 '13 at 00:29
  • I guess it makes sense =) – LucasA Jul 18 '13 at 00:32
  • 2
    I almost never use `git pull`, I always like to preview any upstream changes before I merge them in, so I mostly use `git fetch`. –  Jul 18 '13 at 01:34
  • Usually you don't want to merge your local work-in-progress branch to master yet, so it's better to `git remote update` and `git rebase` until your work is ready to be merged. Otherwise you'll just end up with a number of useless merge commits in the history. – user2061057 Nov 24 '16 at 13:05