我在github.com上有2个分支的公共(public)存储库:mastertest

我在本地创建了一个新目录,并执行了以下操作:

[ ] git clone git@github.com:{username}/{projectname}.git

然后我创建了一个新的名为my_test的分支
[ ] git branch my_test

并切换到它。
[ ] git checkout my_test

然后我将其从我的公共(public)存储库的test分支与
[ ] git merge origin/test

它导致了快速前进。

我进行了一些更改并将其提交。
然后我尝试使用以下命令将本地my_test分支推送到github上的公共(public)test分支:
[ ] git push git@github.com:{username}/{projectname}.git test

但是我得到了这个错误:
error: src refspec test does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'git@github.com:{username}/{projectname}.git

我究竟做错了什么 ?

最佳答案

也许尝试:

git push git@github.com:{username}/{projectname}.git HEAD:test

该命令行上最后一个参数的格式为refspec,它是源ref,后跟冒号,然后是目标ref。您也可以使用本地分支名称(my_test)而不是HEAD来确定要推送正确的分支。

git push 的文档提供了有关此参数的更多详细信息。

关于git - “git push”到github时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/959477/

10-13 08:38
查看更多