Ciro Santilli

fetch

Looks for changes made on a remote repository and brings them in.

The full signature is:

git fetch <remote> <refspec>

where <refspec> is the same as for git push.

You can do a dry run that only lists remote references with ls-remote.

For example, to update you master branch from a remote dev you can do:

git fetch origin dev:master

This will only work for fast-forward changes, because it could be done for any branch, not just the current one, and in that case there is no way to resolve merge conflicts without a working tree.

Omit refspec

Omitting refspec as in:

git fetch <remote>

defaults <refspec> to:

This hasn’t changed in Git 2.0, and is therefore simpler than the default refspec for git push.

Omit remote

Defaults the remote to the first defined of:

FETCH_HEAD

A reference that points to the latest fetched branch.

Common use case: get a single commit not on the main repository, often on the fork feature branch of a pull request, to try it out locally without merging or adding a new remote:

git fetch origin pull/<pr-number>/head
git checkout -b <local-branch-name> FETCH_HEAD