Briefly
git fetch
is similar to pull
but doesn't merge. i.e. it fetches remote updates (refs
and objects
) but your local stays the same (i.e. origin/master
gets updated but master
stays the same) .
git pull
pulls down from a remote and instantly merges.
More
git clone
clones a repo.
git rebase
saves stuff from your current branch that isn't in the upstream branch to a temporary area. Your branch is now the same as before you started your changes. So, git pull -rebase
will pull down the remote changes, rewind your local branch, replay your changes over the top of your current branch one by one until you're up-to-date.
Also, git branch -a
will show you exactly what’s going on with all your branches - local and remote.
This blog post was useful:
The difference between git pull, git fetch and git clone (and git rebase) - Mike Pearce
and covers git pull
, git fetch
, git clone
and git rebase
.
====
UPDATE
I thought I'd update this to show how you'd actually use this in practice.
Update your local repo from the remote (but don't merge):
git fetch
After downloading the updates, let's see the differences:
git diff master origin/master
If you're happy with those updates, then merge:
git pull
Notes:
On step 2: For more on diffs between local and remotes, see: How to compare a local git branch with its remote branch?
On step 3: It's probably more accurate (e.g. on a fast changing repo) to do a git rebase origin
here. See @Justin Ohms comment in another answer.
See also: http://longair.net/blog/2009/04/16/git-fetch-and-merge/