git checkout --track origin / branch和git checkout -b分支源/分支之间的区别 [英] Difference between git checkout --track origin/branch and git checkout -b branch origin/branch

查看:894
本文介绍了git checkout --track origin / branch和git checkout -b分支源/分支之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 显示 git status 和 git branch -v 当检查新分支时,
    • 指示 git pull 不带参数 out



    请参阅

    Does anybody know the difference between these two commands to switch and track a remote branch?

    git checkout -b branch origin/branch
    git checkout --track origin/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:

    • 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.

    (That is, as commented by Sebastian Graf, if the local branch did not exist already.
    If it did, you would need git checkout -B abranch origin/abranch)


    First, some background: Tracking means that a local branch has its upstream set to a remote branch:

    # git config branch.<branch-name>.remote origin
    # git config branch.<branch-name>.merge refs/heads/branch
    


    git checkout -b branch origin/branch will

    • create/reset branch to the point referenced by origin/branch.
    • create the 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 and branch.<name>.merge configuration entries) so that git pull will appropriately merge from the remote-tracking branch.
    This behavior may be changed via the global branch.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 and git 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆