How do you create a remote Git branch?

后端 未结 23 2152
感情败类
感情败类 2020-11-22 13:31

I created a local branch which I want to \'push\' upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch.

Howeve

23条回答
  •  轮回少年
    2020-11-22 14:02

    First, you create your branch locally:

    git checkout -b  # Create a new branch and check it out
    

    The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can do:

    git push   
    

    Where is typically origin, the name which git gives to the remote you cloned from. Your colleagues would then just pull that branch, and it's automatically created locally.

    Note however that formally, the format is:

    git push  :
    

    But when you omit one, it assumes both branch names are the same. Having said this, as a word of caution, do not make the critical mistake of specifying only : (with the colon), or the remote branch will be deleted!

    So that a subsequent git pull will know what to do, you might instead want to use:

    git push --set-upstream   
    

    As described below, the --set-upstream option sets up an upstream branch:

    For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands.

提交回复
热议问题