What's the difference between git “--track” and “--set-upstream-to”?

后端 未结 2 1370
梦谈多话
梦谈多话 2020-12-30 23:07

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 differenc

2条回答
  •  庸人自扰
    2020-12-31 00:06

    Let's assume that you have one master branch which is checked out. Now when you do a

    $ git branch --track someBranch
    

    you will create a new branch named someBranch which changes will be tracked according to the master branch. But this branch has no remote branch set. Thus you see remote = . in the git config.

    Now that someBranch is tracked it means that changes will appear in git status and git branch -v as if a remote exists.

    For example if you make a commit on someBranch git will tell you that you are 1 ahead when you do a git branch -v or when you do a git status it shows you

    Your branch is ahead of 'master' by 1 commit.
    

    And this is the interessting part. The branch is tracked and git shows you that it is 1 commit ahead of master (the branch that was checked out when you created someBranch)

提交回复
热议问题