我试图把我的一个项目推到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

有提示吗?


当前回答

我也得到了同样的错误。我想这是因为我克隆了它,并试图反击。 $ git push -u origin master 这是正确的命令。试试

计数对象:8,完成。 Delta压缩使用最多2个线程。 压缩对象:100%(4/4),完成。 写入对象:100%(8/8),691字节| 46.00 KiB/s,完成。 总共8(1),重用0 (0) remote: resolved deltas: 100% (1/1), done。

[新分支]master -> master 分支主机设置为从原点跟踪远程分支主机。 它很成功。尝试创建新的u分支

其他回答

我有同样的问题,原因是我忘记指定分支

git push myorigin feature/23082018_my-feature_eb

你修复了推送,但是,独立于推送问题(我在“为什么我需要显式地推送一个新分支?”中解释过): 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

这是更好的,克隆这个回购新的。也许它只是迷失了方向。

对我来说,问题来自我的分支名称:“#name-of-my-branch”,没有“#”也可以!

显然,当您在第一次推送时忘记了——all参数时也会得到这个错误消息。我写了

git push -u origin

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

git push -u origin --all

哦,我多么喜欢这些复制粘贴错误……