分支的上游分支或跟踪的远程分支只是在使用git pull和git push命令时默认与之交互的分支.
将分支拉入您的分支时,您可以明确地执行此操作:
git pull origin the_branch
它将获取远程源,然后将origin / the_branch合并到当前分支中.
如果你总是通过设置上游分支来拉动相同的分支,你可以启动git pull:
git branch --set-upstream-to origin/the_branch
git pull
默认情况下,当您从远程分支启动新分支时,git会将其添加为上游分支:
git checkout -b origin/the_branch
# Is equivalent to
git branch --track the_branch origin/the_branch
git checkout the_branch
推动时,几乎是一回事.
配置push.default将确定在使用没有参数的git push时要推送到的默认分支.
使用上游值,它将简单地推入上游分支.
使用默认值simple,它将执行相同的操作,但前提是本地和上游分支名称相同.
我让你看一下doc来检查其他配置的可能性.
您可以使用-vv开关查看所有分支的当前上游分支:
$git branch -vv
* my_branch 33f2d4c [origin/mybranch] a useful commit
master 3ed8e99 [origin/master] Merge
the_branch dbbb8c0 [origin/the_branch] commit on the branch
分支的上游分支也可以使用@ {upstream}引用引用:
$git rev-parse --symbolic-full-name --abbrev-ref @{upstream}
origin/the_branch
push分支作为等价的@ {push}(在99%的用例中它与@ {upstream}相同):
$git rev-parse --symbolic-full-name --abbrev-ref @{push}
origin/the_branch
@ {upstream}和@ {push}之间的区别是针对使用三角形工作流的情况:从只读“上游”项目(通常是上游约定调用的远程)拉出并推送到可写存储库.
这就是GitHub上使用的分叉工作流程的情况.
我发了一篇关于这个的(法国)博客文章,here is the auto-translated version.