How do you create a remote Git branch?

后端 未结 23 1940
感情败类
感情败类 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:04

    Simple Git 2.0+ solution:

    As of Git 2.0, the behavior has become simpler:

    You can configure git with push.default = current to make life easier:

    I added this so now I can just push a new branch upstream with

    $ git push -u
    

    -u will track remote branch of the same name. Now with this configuration, you will auto-guess the remote reference to git push. From git.config documentation:

    push.default

    Defines the action git push should take if no refspec is explicitly given.

    push.default = current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

    For me, this is a good simplification of my day-to-day Git workflow. The configuration setting takes care of the 'usual' use case where you add a branch locally and want to create it remotely. Also, I can just as easily create local branches from remotes by just doing git co remote_branch_name (as opposed to using --set-upstream-to flag).

    I know this question and the accepted answers are rather old, but the behavior has changed so that now configuration options exist to make your workflow simpler.

    To add to your global Git configuration, run this on the command line:

    $ git config --global push.default current
    

提交回复
热议问题