git- Creating a branch which will be pushed to a remote later

后端 未结 3 626
悲哀的现实
悲哀的现实 2021-01-12 01:45

I have a script which automatically creates a new branch with a name based on external information (JIRA ticket). I don\'t want to create the remote branch until I\'ve commi

相关标签:
3条回答
  • 2021-01-12 01:53

    You can do this using the following commands:

    git config branch.mybranch.remote origin
    git config branch.mybranch.merge refs/heads/mybranch
    

    This essentially configures the same thing as --set-upstream-to without checking that the upstream branch already exists first.

    The next step is to change the push.default option, which currently (Git 1.9) defaults to matching (the documentation says this default will change to simple in Git 2.0). Using matching won't do what you want because there is no matching branch at the upstream remote yet. So:

    git config push.default simple
    

    You can set this globally (for all your repositories) using the --global switch.

    After doing this, a

    git push
    

    will push the current branch (and only the current branch) to its upstream (which you set above), creating the upstream branch if necessary.

    0 讨论(0)
  • 2021-01-12 02:12

    You can use the -u option when you push to track your local branch

    git push -u origin myBranch
    

    http://csurs.csr.uky.edu/cgi-bin/man/man2html?1+git-push

    0 讨论(0)
  • 2021-01-12 02:14

    Try --track instead of --set-upstream-to, eg:

    git branch --track origin/mynewbranch

    I haven't found out exactly what the difference between the two is, but --track seems to do what you're wanting (and what I was wanting to do when I found this question!)

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