我试图把我的一个项目推到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
所以我试了一下,得到了这个:
peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master
fatal: Authentication failed
另一个stackoverflow线程建议我尝试以下方法,但结果令人失望。
peeplesoft@jane3:~/846156 (master) $ git push -u origin master
fatal: Authentication failed
然后我试了一下:
peeplesoft@jane3:~/846156 (master) $ git config remote.origin.push HEAD
peeplesoft@jane3:~/846156 (master) $ git push
fatal: Authentication failed
有提示吗?
我在上传的时候也遇到了同样的问题,我解决了
做着上面说的同样的事情:
早些时候,我试图通过https将终端推送到linux中的存储库
就像
git push https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git
但没有任何结果,因此我更深入地尝试:
git push --set-upstream https://github.com/SiddharthChoudhary/ClientServerCloudComputing.git master
这招奏效了。这样就会提示您输入用户名和密码。
我还生成了一个令牌,而不是密码,我粘贴令牌,因此,成功完成。
要生成一个令牌,请转到您的Github帐户,在开发者设置中,然后创建另一个令牌。
收到后,收到
该令牌并在被询问时粘贴到密码提示中。
你修复了推送,但是,独立于推送问题(我在“为什么我需要显式地推送一个新分支?”中解释过): git push -u origin master或git push -u origin——all),你现在需要解决身份验证问题。
这取决于你的url (ssh在'git@github.com/yourRepo,或https在https://github.com/You/YourRepo)
对于https url:
如果您的帐户受到双重身份验证的保护,您的常规密码将不起作用(https url),如这里或这里所解释的。
如果您的密码包含特殊字符(如这个答案),也会出现同样的问题。
如果https不起作用(因为您不想生成辅助密钥,即PAT:个人访问令牌),那么您可以切换到ssh,如我在这里所示。
正如qwerty在评论中所指出的,你可以在远程上自动创建同名的分支:
git push -u origin head
Why?
HEAD(查看你的.git\HEAD文件)有当前签出分支的refspec(例如:ref: refs/heads/master)
默认的推送策略很简单
因为这个推送使用的refpec是head:(没有目标),所以缺少:<dst>意味着更新与<src> (head,这是一个分支)相同的ref。
这将不会工作,如果头部是分离的。
或者你可以使用Git 2.37 (Q3 2022)和新的全局选项push.autoSetupRemote:
git config --global push.autoSetupRemote true
git push