gittrack_什么时候使用git branch –track(开始“看上游”的意思)?

分支的上游分支或跟踪的远程分支只是在使用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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值