git checkout --track origin / branch和git checkout -b分支源/分支之间的区别 [英] Difference between git checkout --track origin/branch and git checkout -b branch origin/branch
问题描述
git checkout -b分支原点/ branch
git checkout --track origin / branch
我认为双方都跟踪远程分支,所以我可以把我的变化推到原产地的分支上吧?
是否存在实际差异?
谢谢!
这两个命令具有相同的效果(感谢Robert Siemer的回答,指出了这一点)。
实际的区别在于使用不同的本地分支::
-
git checkout -b mybranch origin / abranch
会创建mybranch
并跟踪origin / abranch
-
git checkout --track origin / abranch
只会创建'',不是名称不同的分支。
(也就是评论通过塞巴斯蒂安格拉夫,如果本地分支不存在已经存在。
如果是这样,你需要 git checkout -B abranch origin / abranch
)
首先,一些背景:跟踪表示本地分支的上游设置为偏远麸皮ch:
#git config分支。<分支名称> .remote原产地
#git config分支。< ;分支名称> .merge refs / heads / branch
<创建/重置 git checkout -b分支源/分支将 code>分支到
origin / branch
。引用的点。分支
(使用 git分支
)并跟踪远程跟踪分支 origin / branch
。
当本地分支从远程追踪分支启动时,Git设置分支(特别是
分支。< name> .remote
和分支。< name> .merge
配置条目)git pull
会从远程跟踪分支适当地合并。
这种行为可以通过全局branch.autosetupmerge
配置标志。该设置可以通过使用- track
和- no-track
选项来覆盖,稍后使用git进行更改分行- 设定上游至
。
和 git checkout --track origin / branch
会做同样的事情:
#或者自1.7.0
git branch --set-upstream branch upstream / branch
#或者自1.8.0(2012年10月)开始
git分支--set-upstream-to分支上游/分支
#短版本保持不变:
git分支-u分支上游/分支
它还会为'分支
'设置上游。
(注意:git1.8.0将会弃用
git branch --set-upstream
并将其替换为 git branch -u | --set-上游 -
:参见 git1.8.0-rc1宣布) 注册为本地分支的上游分支将会:
git status
和 git branch -v
。 当检查新分支时,
git pull
不带参数 out 。
请参阅 Does anybody know the difference between these two commands to switch and track a remote branch? I think both keep track of the remote branch so I can push my changes to the branch on origin, right? Is there any practical differences?? Thanks! The two commands have the same effect (thanks to Robert Siemer’s answer for pointing it out). The practical difference comes when using a local branch named differently: (That is, as commented by Sebastian Graf, if the local branch did not exist already. First, some background: Tracking means that a local branch has its upstream set to a remote branch:
git checkout -b branch origin/branch
git checkout --track origin/branch
git checkout -b mybranch origin/abranch
will create mybranch
and track origin/abranch
git checkout --track origin/abranch
will only create 'abranch
', not a branch with a different name.
If it did, you would need git checkout -B abranch origin/abranch
)
# git config branch.<branch-name>.remote origin
# git config branch.<branch-name>.merge refs/heads/branch
git checkout -b branch origin/branch
will
branch
to the point referenced by origin/branch
.branch
(with git branch
) and track the remote tracking branch origin/branch
.
When a local branch is started off a remote-tracking branch, Git sets up the branch (specifically the
branch.<name>.remote
andbranch.<name>.merge
configuration entries) so thatgit pull
will appropriately merge from the remote-tracking branch.
This behavior may be changed via the globalbranch.autosetupmerge
configuration flag. That setting can be overridden by using the--track
and--no-track
options, and changed later using git branch--set-upstream-to
.
And git checkout --track origin/branch
will do the same:
# or, since 1.7.0
git branch --set-upstream branch upstream/branch
# or, since 1.8.0 (October 2012)
git branch --set-upstream-to branch upstream/branch
# the short version remains the same:
git branch -u branch upstream/branch
It would also set the upstream for 'branch
'.
(Note: git1.8.0 will deprecate git branch --set-upstream
and replace it with git branch -u|--set-upstream-to
: see git1.8.0-rc1 announce)
Having an upstream branch registered for a local branch will:
- tell git to show the relationship between the two branches in
git status
andgit branch -v
. - directs
git pull
without arguments to pull from the upstream when the new branch is checked out.
See "How do you make an existing git branch track a remote branch?" for more.
这篇关于git checkout --track origin / branch和git checkout -b分支源/分支之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!