git-创建一个分支,稍后将其推送到远程 [英] git- Creating a branch which will be pushed to a remote later
问题描述
我有一个脚本,它会根据外部信息(JIRA票证)自动创建一个名称为新的分支。我不想创建远程分支,直到我提交并推送了一些代码,但我不想做git push --set-upstream origin。
换句话说,我想在推送之前设置上游。
git checkout -b mybranch
git< do-something-to-prepare origin / mybranch without talk to origin>
git commit -a -m完成我的更改。
git push
我试过了:
git branch --set-upstream-to = origin / mynewbranch
结果如下:
错误:请求的上游分支'origin / mynewbranch'不存在。
有没有办法做到这一点?
git config branch.mybranch .remote origin
git config branch.mybranch.merge refs / heads / mybranch
配置与 - set-upstream-to
相同的东西,而不检查上游分支是否已经先存在。
下一步是更改 push.default
选项,该选项当前(Git 1.9)默认为匹配
(文档说这个默认值在Git 2.0中会变成 simple
)。使用匹配
不会做你想做的事情,因为在上游远端还没有匹配的分支。所以:
git config push.default简单
您可以使用 - global
开关在全局范围内(对于所有存储库)进行设置。
完成此操作后,一个
git push
会将当前分支(只有当前分支)推送到其上游(您在上面设置),如有必要,创建上游分支。
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 committed and pushed some code, but I don't want to have to do "git push --set-upstream origin"
In other words, I want to set the upstream before I push.
git checkout -b mybranch
git <do-something-to-prepare origin/mybranch without talking to origin>
<do work>
git commit -a -m "Made my changes."
git push
I've tried:
git branch --set-upstream-to=origin/mynewbranch
This results in:
error: the requested upstream branch 'origin/mynewbranch' does not exist.
Is there any way to do this?
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.
这篇关于git-创建一个分支,稍后将其推送到远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!