gpt4 book ai didi

git - 致命的 : The current branch master has no upstream branch

转载 作者:IT王子 更新时间:2023-10-29 01:16:48 29 4
gpt4 key购买 nike

我正在尝试将我的一个项目推送到 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

有什么提示吗?

最佳答案

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

这取决于您的网址(ssh,如“git@github.com/yourRepo”,或 https,如 https://github.com/You/YourRepo)

对于 https 网址:

如果您的帐户受 two-factor authentication 保护,您的常规密码将无效(对于 https 网址),as explained here or here .

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

如果 https 不起作用(因为您不想生成辅助 key ,PAT:个人访问 token ),那么您可以切换到 ssh,as I have shown here .


qwerty 所述在评论中,您可以使用以下命令在远程自动创建同名分支:

git push -u origin head 

为什么?

  • HEAD(查看您的 .git\HEAD 文件)具有当前 checkout 分支的 refspec(例如:ref: refs/heads/master)
  • 默认push policy simple

由于用于此推送的 refpec 是 head:(无目的地),因此缺少 :<dst>意味着更新与 <src> 相同的引用(头,这是一个分支)。

如果 HEAD is detached 那将不起作用虽然。


或者您可以使用 Git 2.37 (Q3 2022) and the new global option push.autoSetupRemote :

git config --global push.autoSetupRemote true
git push

关于git - 致命的 : The current branch master has no upstream branch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23401652/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com