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

有提示吗?


当前回答

不同的情况下,相同的错误(备份到外部驱动器),问题是我设置了远程回购与克隆。如果你一开始就用bare设置远程回购,每次都有效

cd F:/backups/dir
git init --bare
cd C:/working/dir
git remote add backup F:/backups/dir
git push backup master

其他回答

首先使用git拉原点your_branch_name 然后使用git push origin your_branch_name

在我看来,这只是一个错误的默认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 -u origin 'your branch name'

这段代码将在远程存储库中创建您的分支,并将它…

在我的情况下,我有一个本地分支称为Master,而Master是在Github上。 我只是把我的Master ->重命名为Master,然后签出为Master。 然后按一下。这对我很管用。

如果你在尝试一个新的本地分支的git推送后经常得到以下git错误消息:

致命:当前分支没有上游分支。

要推动当前分支并将远程设置为上游,请使用

git push --set-upstream origin <branchname>

然后,问题是您没有配置git总是从本地分支创建远程的新分支。

如果你总是想在远程上创建一个新的分支来镜像和跟踪你的本地分支,永久的修复方法是:

git config --global push.default current

现在你可以毫无错误地推git了!

https://vancelucas.com/blog/how-to-fix-git-fatal-the-current-branch-has-no-upstream-branch/