「git fetch使用方法及示例」


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.

Peek at a remote’s branch, without configuring the remote in your local repository

$ git fetch git://git.kernel.org/pub/scm/git/git.git maint
$ git log FETCH_HEAD

The first command fetches the maint branch from the repository at
git://git.kernel.org/pub/scm/git/git.git and the second command uses FETCH_HEAD to examine the branch
with git-log(1). The fetched objects will eventually be removed by git’s built-in housekeeping (see git-gc(1)).



# --all:获取所有的远程分支。
# --tags:同时获取所有的远程tags。
# --prune:fetch前移除那些在remote中已经不存在的分支。
git fetch --all --tags --prune

# 移除查看所有tag
git tag

# 先 git clone 整个仓库,然后 git checkout tag_name 就可以取得 tag 对应的代码了。
# 但是这时候 git 可能会提示你当前处于一个“detached HEAD" 状态,因为 tag 相当于是一个快照,是不能更改它的代码的,如果要在 tag 代码的基础上做修改,你需要一个分支:
# 检出某个tag
git checkout -b <bnew-branch-name> <tag-name>