fetch

Send to Kindle
home » snippets » git » fetch


Notes

Update the remote-tracking branches:

$ git fetch origin

The above command copies all branches from the remote refs/heads/ namespace and stores them to the local refs/remotes/origin/ namespace, unless the branch.<name>.fetch option is used to specify a non-default refspec.

Using refspecs explicitly:

$ git fetch origin +pu:pu maint:tmp

This updates (or creates, as necessary) branches pu and tmp in the local repository by fetching from the branches (respectively) pu and maint from the remote repository.

The pu branch will be updated even if it is does not fast-forward, because it is prefixed with a plus sign; tmp will not be.

Examples

# Create a local branch corresponding to the remote
# branch that is fetched.
git fetch remote_name remote_branch_name:local_branch_name

# As before, but if there is a existing
# local_branch_name, then force update it.
git fetch remote_name +remote_branch_name:local_branch_name