“git push”到github时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/959477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error when "git push" to github
提问by ebsbk
I have a public repository at github.com with 2 branches : master
and test
.
我在 github.com 有一个公共存储库,有 2 个分支:master
和test
.
I created a new directory locally and did:
我在本地创建了一个新目录并执行了以下操作:
[ ] git clone [email protected]:{username}/{projectname}.git
Then I created a new branch named my_test
with
然后,我创建了一个名为新的分支my_test
与
[ ] git branch my_test
and switched to it.
并切换到它。
[ ] git checkout my_test
Then I merged it from my test
branch of my public repository with
然后我将它从我test
的公共存储库的分支与
[ ] git merge origin/test
and it resulted in a fast forward.
这导致了快进。
I made some changes and committed them.
Then I tried to push the local my_test
branch to the public test
branch at github with
我做了一些更改并提交。然后我尝试将本地my_test
分支推送到test
github的公共分支
[ ] git push [email protected]:{username}/{projectname}.git test
but I got this error:
但我收到了这个错误:
error: src refspec test does not match any.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '[email protected]:{username}/{projectname}.git
What am I doing wrong ?
我究竟做错了什么 ?
回答by Greg Hewgill
Perhaps try:
也许尝试:
git push [email protected]:{username}/{projectname}.git HEAD:test
The format of the last parameter on that command line is a refspecwhich is a source ref followed by a colon and then the destination ref. You can also use your local branch name (my_test
) instead of HEAD to be certain you're pushing the correct branch.
该命令行上最后一个参数的格式是一个refspec,它是一个源引用,后跟一个冒号,然后是目标引用。您还可以使用本地分支名称 ( my_test
) 而不是 HEAD 来确定您正在推送正确的分支。
The documentation for git push
has more detail on this parameter.
的文档git push
有关于此参数的更多详细信息。
回答by Scott Chacon
Also, you don't need to type out the whole url each time you want to push. When you ran the clone, git saved that URL as 'origin', that's why you can run something like 'merge origin/test' - it means the 'test' branch on your 'origin' server. So, the simplest way to push to your server in that case would be:
此外,您不需要每次要推送时都输入整个 url。当您运行克隆时,git 将该 URL 保存为“origin”,这就是为什么您可以运行“merge origin/test”之类的东西 - 这意味着“origin”服务器上的“test”分支。因此,在这种情况下推送到服务器的最简单方法是:
git push origin my_test:test
That will push your local 'my_test' branch to the 'test' branch on your 'origin' server. If you had named your local branch the same as the branch on the server, then the colon is not neccesary, you can simply do:
这会将您的本地 'my_test' 分支推送到您的 'origin' 服务器上的 'test' 分支。如果您将本地分支命名为与服务器上的分支相同,则不需要冒号,您可以简单地执行以下操作:
git push origin test
回答by Ken
This error also comes up if you try to push to a new repository without having committed anything first. Try:
如果您尝试推送到新存储库而没有先提交任何内容,也会出现此错误。尝试:
git add -A
git commit -am 'Initial commit'
And then try your push again.
然后再次尝试推送。
回答by First Zero
I think here you will need to set up branch tracking. Please run the following to enable tracking
我认为在这里您需要设置分支跟踪。请运行以下命令以启用跟踪
git branch --track my_test origin/my_test
To test
去测试
git push -u origin my_test
git pull origin my_test
回答by Gal Bracha
You need to make sure that your local repository have the same name as your remote repository you're trying to push.
您需要确保您的本地存储库与您尝试推送的远程存储库具有相同的名称。
First, change repository using git branch -m "test" so that "my_test" would be "test". Second, just git push origin test
首先,使用 git branch -m "test" 更改存储库,以便 "my_test" 为 "test"。二、只需 git push origin test