What does '--set-upstream' do?

前端 未结 3 911
我在风中等你
我在风中等你 2020-11-28 17:20

What does git --set-upstream do?

I tried to understand it by reading the git manual, but I didn\'t quite get it.

相关标签:
3条回答
  • 2020-11-28 17:53
    git branch --set-upstream <remote-branch>
    

    sets the default remote branch for the current local branch.

    Any future git pull command (with the current local branch checked-out),
    will attempt to bring in commits from the <remote-branch> into the current local branch.


    One way to avoid having to explicitly type --set-upstream is to use its shorthand flag -u as follows:

    git push -u origin local-branch
    

    This sets the upstream association for any future push/pull attempts automatically.
    For more details, checkout this detailed explanation about upstream branches and tracking.


    To avoid confusion, recent versions of git deprecate this somewhat ambiguous --set-upstream option in favour of a more verbose --set-upstream-to option with identical syntax and behaviour

    git branch --set-upstream-to <origin/remote-branch>
    
    0 讨论(0)
  • 2020-11-28 17:56

    git branch --set-upstream <<origin/branch>> is officially not supported anymore and is replaced by git branch --set-upstream-to <<origin/branch>>

    0 讨论(0)
  • 2020-11-28 18:01

    When you push to a remote and you use the --set-upstream flag git sets the branch you are pushing to as the remote tracking branch of the branch you are pushing.

    Adding a remote tracking branch means that git then knows what you want to do when you git fetch, git pull or git push in future. It assumes that you want to keep the local branch and the remote branch it is tracking in sync and does the appropriate thing to achieve this.

    You could achieve the same thing with git branch --set-upstream-to or git checkout --track. See the git help pages on tracking branches for more information.

    0 讨论(0)
提交回复
热议问题