我试图把我的一个项目推到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操作,那么如果命令行上没有给出refspec,远程中没有配置refspec,并且命令行上给出的任何选项都没有暗示refspec,它就会执行该操作。

尽管去做吧:

git config --global push.default current

然后

git push

其他回答

在我看来,这只是一个错误的默认git行为。 回顾了git支持的所有选项,也回顾了相关的git代码:

https://github.com/git/git/blob/140045821aa78da3a80a7d7c8f707b955e1ab40d/builtin/push.c#L188

我建议最好的解决方案是重写push default命令:

git config --global alias.pu 'push -u'

这基本上改变了推送的默认行为,所以这是有意义的。

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

尽管去做吧:

git config --global push.default current

然后

git push

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

git remote add origin url-to-your-repo

实际的指令

对我来说,我正在将更改推到一个我没有写访问权的私有回购。 在执行推或拉操作时,请确保您拥有有效的访问权限。

您可以直接验证通过

为了解决这个问题,在从git中检出代码时,你需要给出如下命令:

Git checkout -b branchname origin/branchname

在这里,默认情况下我们正在设置上游分支,因此您将不会遇到上述问题。