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

有提示吗?


当前回答

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

其他回答

如果您定义了git push操作,那么如果命令行上没有给出refspec,远程中没有配置refspec,并且命令行上给出的任何选项都没有暗示refspec,它就会执行该操作。

尽管去做吧:

git config --global push.default current

然后

git push

如果您试图将代码直接推到主分支,则使用命令

git push origin master

这对我有帮助。

遇到了几乎相同的问题,但不是来自主分支。 我尝试推两个(2)分支到我的远程存储库,通过使用$ git push命令;不幸地抛出了:

fatal: The current branch <branch-name> has no upstream branch. To push the current branch and set the remote as upstream, use

 git push --set-upstream origin <branch-name>

我用下面的命令修复了它:

$ git push -u origin --all

PS:这里提供的解决方案应该,我相信,让git更容易远程跟踪分支;有一天,当处理有几个分支的项目时,这可能会派上用场。

帮助我的是: 我发现我的目录和git之间的连接没有建立 所以我又做了一次: Git push -u origin main

您需要先配置遥控器,然后再按。

git remote add origin url-to-your-repo

实际的指令