在git中,为什么创建远程分支需要本地分支?

时间:2017-05-25 03:46:56

标签: git

我试图理解为什么我无法创建具有有效引用的远程分支,例如head^或SHA。

git push origin SHA:test
git push origin head^:test

这两个命令都失败了:

error: unable to push to unqualified destination: test
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.
error: failed to push some refs to 'remote'

这迫使我创建并立即删除一个看似愚蠢的本地分支

git branch tmp head^
git push origin tmp:test
git branch -D tmp

有更简单的方法吗?

请注意,如果origin/test已存在,前两个命令就会成功。

1 个答案:

答案 0 :(得分:2)

git push origin SHA:refs/heads/test

将在origin远程创建test分支。 (如果您不需要默认值,也可以按URL或路径名指定遥控器。)

分支引用是以refs/heads开头的引用。标记引用是以refs/tags开头的引用。远程跟踪引用启动refs/remotes/remote。所以当你说git push origin SHA:test时,没有任何关于git工作的例子就必须简单猜测。

相关问题