创建一个将在稍后推送到远程的分支
我有一个脚本,它会根据外部信息(JIRA票证)自动创建一个带有名称的新分支。 我不想创建远程分支,直到我提交并推送了一些代码,但我不想做“git push --set-upstream origin”
换句话说,我想在推动之前设置上游。
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
我试过了:
git branch --set-upstream-to=origin/mynewbranch
这导致:
error: the requested upstream branch 'origin/mynewbranch' does not exist.
有没有办法做到这一点?
您可以使用以下命令执行此操作:
git config branch.mybranch.remote origin
git config branch.mybranch.merge refs/heads/mybranch
这基本上与--set-upstream-to
配置相同的东西--set-upstream-to
而不检查上游分支是否已经先存在。
下一步是更改push.default
选项,该选项当前(Git 1.9)默认为matching
(文档说这个默认将在Git 2.0中变为simple
)。 使用matching
不会做你想做的事情,因为在上游远程还没有匹配的分支。 所以:
git config push.default simple
您可以使用--global
开关全局设置(针对所有存储库)。
做完这些之后,a
git push
将当前分支(并且仅当前分支)推送到其上游(您在上面设置),如果需要则创建上游分支。
当您推动追踪您的本地分支时,您可以使用-u
选项
git push -u origin myBranch
http://csurs.csr.uky.edu/cgi-bin/man/man2html?1+git-push
试试看--track
而不是--set-upstream-to
,例如:
git branch --track origin/mynewbranch
我还没有找到两者之间的区别,但--track
似乎做你想做的事(当我发现这个问题时我想做的事情!)
上一篇: Creating a branch which will be pushed to a remote later