远程跟踪分支
您的本地 Git 存储库包含对它所连接的远程存储库上分支状态的引用。这些本地引用称为远程跟踪分支。
您可以使用以下命令查看远程跟踪分支。
# list all remote branches
git branch -r
若要更新远程跟踪分支而不更改本地分支,请使用该命令。git fetch
删除本地 Git 存储库中的远程分支是安全的,这不会影响远程存储库。下次运行该命令时,将重新创建远程分支。为此,您可以使用以下命令。git fetch
# delete remote branch from origin
git branch -d -r origin/[remote_branch]
删除远程分支
要删除远程存储库中的分支,请使用以下命令。
# delete branch in a remote repository
git push [remote] --delete [branch]
跟踪分支
分支可以跟踪另一个分支。这称为具有上游分支,此类分支可以称为跟踪分支。
跟踪分支允许您直接使用 and 命令,而无需指定分支和存储库。git pullgit push
如果克隆 Git 存储库,则 Git 会将本地主分支创建为源存储库主分支(简称:源/主)的跟踪分支。
通过在创建分支期间指定远程分支来创建新的跟踪分支。下面的示例演示了这一点。
# setup a tracking branch called newbranch
# which tracks origin/newbranch
git checkout -b newbranch origin/newbranch
除了使用命令之外,您还可以使用该命令。git checkoutgit branch
# origin/master used as example, but can be replaced
# create branch based on remote branch
git branch [new_branch] origin/master
# use --track,
# default when the start point is a remote-tracking branch
git branch --track [new_branch] origin/master
该选项允许您指定不想跟踪分支。您可以稍后使用该命令显式添加跟踪分支。–no-trackgit branch -u
# instruct Git to create a branch which does
# not track another branch
git branch --no-track [new_branch_notrack] origin/master
# update this branch to track the origin/master branch
git branch -u origin/master [new_branch_notrack]
要查看远程存储库(简称:remote)的跟踪分支,可以使用以下命令。
# show all remote and tracking branches for origin
git remote show origin
此示例输出可能如下所示。
* remote origin
Fetch URL: ssh://xq.org/gitroot/e4/org.eclipse.e4.tools.git
Push URL: ssh://xq/gitroot/e4/org.eclipse.e4.tools.git
HEAD branch: master
Remote branches:
integration tracked
interm_rc2 tracked
master tracked
smcela/HandlerAddonUpdates tracked
Local branches configured for 'git pull':
integration rebases onto remote integration
master rebases onto remote master
testing rebases onto remote master
Local refs configured for 'git push':
integration pushes to integration (up to date)
master pushes to master (up to date)