gittrack_git“ - track”的区别是什么?和“设置 - 上游到”?

As I can see, both git --track and --set-upstream-to modify a branch so it becames a tracking (or upstream) branch. But where is a subtle difference I can't comprehend. The --track records "remote branch tracks local":

$ git checkout foo -b

$ git branch --track origin/retarget

Branch origin/retarget set up to track local branch foo.

$ cat .git/config

[branch "origin/retarget"]

remote = .

merge = refs/heads/foo

While --set-upstream-to records "local branch tracks remote branch":

$ git checkout foo -b

$ git branch --set-upstream-to origin/retarget

Branch foo set up to track remote branch retarget from origin.

$ cat .git/config

[branch "foo"]

remote = origin

merge = refs/heads/retarget

What's the difference between this two? I was sure that "tracking branch" is simple concept with additional upstream pointer inside branch that tracks head position of specified branch in remote repository. But seems it's much more complicated?

解决方案$ git checkout foo -b

$ git branch --track origin/retarget

The first two commands instruct git to:

create a local branch named "origin/retarget" (very bad idea, as it is named as a remote tracking branch", while it is actually a simple local branch with a '/' in its name)

starting from the current branch ("foo", another local branch)

to make that new local branch tracking its starting point.

--track

When creating a new branch, set up branch..remote and branch..merge configuration entries to mark the start-point branch as "upstream" from the new branch.

You would use track when you create a branch starting from a remote tracking one.

In other word, your first example isn't how you would use --track.

This would work better:

git checkout -b foo --track origin/retarget

As for the difference between --track and --set-upstream-to:

--set-upstream-to

If specified branch does not exist yet or if --force has been given, acts exactly like --track.

Otherwise sets up configuration like --track would when creating the branch, except that where branch points to is not changed.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值