2014-05-01 61 views
70

我试图把我的项目的github的一个,和我不断收到此错误:致命:当前分支主没有上游分支

[email protected]:~/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 

于是,我尝试过了,得到这个:

[email protected]:~/846156 (master) $ git push --set-upstream origin master 

fatal: Authentication failed 

另一个stackoverflow线程建议我尝试以下,结果令人失望。

[email protected]:~/846156 (master) $ git push -u origin master 

fatal: Authentication failed 

然后我尝试这样的:

[email protected]:~/846156 (master) $ git config remote.origin.push HEAD 

[email protected]:~/846156 (master) $ git push 

fatal: Authentication failed 

任何提示?

+1

回购必须存在于github _before_您可以推送到它。可以?你正在与克隆它的回购? – matt

+0

我克隆了Github的repo,然后在自述文件中添加了1行,然后尝试将其推回。 – user1524361

回答

23

您修复了推送,但与推送问题无关(我在“Why do I need to explicitly push a new branch?”中解释过:git push -u origin mastergit push -u origin --all),您现在需要解决身份验证问题。

这取决于你的网址(SSH为“[email protected]/yourRepo,或https为https://github.com/You/YourRepo

对于HTTPS URL:

如果您的帐户是由two-factor authentication保护,您的常规密码将无法正常工作(用于https url),as explained hereor here

您的密码包含特殊字符(如this answer)同样的问题

如果HTTPS不工作(因为你不希望产生二级密钥,PAT:个人访问令牌),那么你可以切换到ssh,as I have shown here

66

您也可以使用下面的命令:

git push -u origin master 

这将创建(-u)在远程回购另一个分支。一旦使用ssh进行身份验证就完成了。

+1

这与问题确实有关,因为问题在于验证。他还表示,他已经在他的职位上尝试过。 –

+6

来自谷歌,这个答案解决了我的问题。 +1 – HAL9000

22

显然,当您第一次推送时忘记--all参数,您也会收到此错误消息。我写

git push -u origin 

这给了这个错误,它应该是

git push -u origin --all 

我多么喜欢这些复制 - 粘贴错误...

+2

谢谢。我在Visual Studio Code中遇到了这个错误,并且这个工作很奏效,但是在多个开发人员的环境中,有人可以解释这是什么吗? – o365spo

0

的计算机和您的GitHub相关。使用SSH。计算机代码,所以你不需要提交验证enter image description here

2. git无法管理空文件夹。所以你必须写一个这样的readme.md保存在一个文件中。否则,您将无法找到该文件。

3.您的本地项目并不是新项目移过来的。请

git init

git remote add origin +"githublink"

git add .

git commit -m ""着呢。

4.然后git pull origin master(关键)

5.最后git push origin master(解决所有的问题)。

http://my.oschina.net/psuyun/blog/123005参考链接

2

首先使用git pull origin your_branch_name 然后use git push origin your_branch_name

+0

对不起如果这听起来很愚蠢。如何了解我的分行名称。我的回购在AWS中。 – Pravin

2

您需要配置远程第一,然后推。

git remote add origin url-to-your-repo 

Actual Instructions

1

有一个简单的解决方案,这里面为我工作在MacOS塞拉利昂。 我做了以下两条命令:

git pull --rebase git_url(Ex: https://github.com/username/reponame.git) 
git push origin master 

如果显示有任何未来的推后,关于上游的任何致命错误,然后只需运行:

git push --set-upstream origin master 
-1

要解决此问题,而从git自己检查出的代码,U需要给命令象下面这样:

git checkout -b branchname origin/branchname

这里,由德我们正在设置the upstream branch,所以你不会面临上述问题。

相关问题