git 致命:当前分支 master 没有上游分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23401652/
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
fatal: The current branch master has no upstream branch
提问by user1524361
I'm trying to push one of my projects to github, and I keep getting this error:
我正在尝试将我的一个项目推送到 github,但我不断收到此错误:
peeplesoft@jane3:~/846156 (master) $ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
So I tried it and got this:
所以我试了一下,得到了这个:
peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master
fatal: Authentication failed
Another stackoverflow thread suggested I try the following, with disappointing results.
另一个 stackoverflow 线程建议我尝试以下操作,但结果令人失望。
peeplesoft@jane3:~/846156 (master) $ git push -u origin master
fatal: Authentication failed
Then I tried this:
然后我尝试了这个:
peeplesoft@jane3:~/846156 (master) $ git config remote.origin.push HEAD
peeplesoft@jane3:~/846156 (master) $ git push
fatal: Authentication failed
Any hints?
任何提示?
采纳答案by VonC
You fixed the push, but, independently of that push issue (which I explained in "Why do I need to explicitly push a new branch?": git push -u origin master
or git push -u origin --all
), you need now to resolve the authentication issue.
你固定的推动,但是,独立于推动问题的(这是我在解释“为什么我需要显式地推一个新的分支?”:git push -u origin master
或git push -u origin --all
),现在需要解决的身份验证问题。
That depends on your url (ssh as in '[email protected]/yourRepo
, or https as in https://github.com/You/YourRepo
)
这取决于您的网址(ssh 中的 '[email protected]/yourRepo
或 https 中的https://github.com/You/YourRepo
)
For https url:
对于 https 网址:
If your account is protected by the two-factor authentication, your regular password won't work (for https url), as explained hereor here.
如果您的帐户受双因素身份验证保护,则您的常规密码将不起作用(对于 https url),如此处或此处所述。
Same problem if your password contains special character (as in this answer)
如果您的密码包含特殊字符,同样的问题(如本答案)
If https doesn't work (because you don't want to generate a secondary key, a PAT: personal Access Token), then you can switch to ssh, as I have shown here.
如果 https 不起作用(因为您不想生成辅助密钥 PAT:个人访问令牌),那么您可以切换到 ssh,如我在此处所示。
As noted by qwertyin the comments, you can automatically create the branch of same name on the remote with:
正如qwerty在评论中所指出的,您可以使用以下命令在遥控器上自动创建同名分支:
git push -u origin head
Why?
为什么?
- HEAD (see your
.git\HEAD
file) has the refspec of the currently checked out branch (for example:ref: refs/heads/master
) - the default push policyis simple
Since the refpec used for this push is head: (no destination), a missing :<dst>
means to update the same ref as the <src>
(head, which is a branch).
由于用于此推送的 refpec 是 head:(无目的地),因此缺少:<dst>
更新与<src>
(head,这是一个分支)相同的 ref 的方法。
That won't work if HEAD is detachedthough.
如果HEAD 分离,那将不起作用。
回答by TantrajJa
Also you can use the following command:
您也可以使用以下命令:
git push -u origin master
This creates (-u) another branch in your remote repo. Once the authentication using ssh is done that is.
这会在您的远程仓库中创建 (-u) 另一个分支。一旦完成使用 ssh 的身份验证。
回答by TheEye
Apparently you also get this error message when you forget the --all
parameter when pushing for the first time. I wrote
显然,当您--all
第一次推送时忘记参数时,您也会收到此错误消息。我写
git push -u origin
which gave this error, it should have been
这给出了这个错误,它应该是
git push -u origin --all
Oh how I love these copy-paste errors ...
哦,我多么喜欢这些复制粘贴错误......
回答by Santosh Pillai
You need to configure the remote first, then push.
您需要先配置遥控器,然后推送。
git remote add origin url-to-your-repo
回答by lorem
Please try this scenario
请试试这个场景
git push -f --set-upstream origin master
回答by DariusV
If you define the action git push
it should take it if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line.
如果您定义了git push
在命令行上没有给出 refspec、没有在远程配置 refspec 并且命令行上给出的任何选项都没有暗示 refspec 的情况下应该采取的操作。
Just do it:
去做就对了:
git config --global push.default current
then
然后
git push
回答by Siddharth Choudhary
Well, I was having the same trouble while uploading and I resolved it by doing the same thing which it says to do: Earlier I was trying to push through terminal to my repository in linux by https like
好吧,我在上传时遇到了同样的问题,我通过做它所说的同样的事情来解决它:早些时候我试图通过 https 将终端推送到我在 linux 中的存储库,例如
git push https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git
But was not getting any result and hence I went down deeper and tried:
但是没有得到任何结果,因此我更深入地尝试:
git push --set-upstream https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git master
And it worked. Thus then you will get prompted with username and password. I also generated a tokenand instead of Password I pasted the token and thus, being done successfully.
它奏效了。因此,您将收到用户名和密码的提示。我还生成了一个令牌,而不是密码,我粘贴了令牌,因此成功完成。
- To generate a token go to your Github account and in Developer Settings and then create another token.
- After getting that, copy that token and paste in the password prompt when it's been asked.
- 要生成令牌,请转到您的 Github 帐户和开发人员设置,然后创建另一个令牌。
- 获得该令牌后,复制该令牌并在询问时粘贴密码提示。
回答by Abhishek
on a very simple side, once you have other branches, you can't just use for pushing a branch
在一个非常简单的方面,一旦你有其他分支,你就不能只用于推送一个分支
git push
But you need to specify the branch now, even if you have checkout the branch you want to push, so
但是你现在需要指定分支,即使你已经结帐了你想要推送的分支,所以
git push origin <feature_branch>
Where can be even the master
branch
哪里可以连master
分行
回答by yl_low
I made the simple error of forgetting to commit:
我犯了忘记提交的简单错误:
git commit -m "first commit"
then git push origin master
worked.
然后git push origin master
工作。