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

然后配置您的邮件id使用

git config user.email "example@example.com"

这是我的工作

其他回答

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

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

尽管去做吧:

git config --global push.default current

然后

git push

遇到了几乎相同的问题,但不是来自主分支。 我尝试推两个(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更容易远程跟踪分支;有一天,当处理有几个分支的项目时,这可能会派上用场。

1. 一台电脑和你的github相关联。使用SSH。计算机代码,所以你不需要提交验证输入图像说明这里

2. Git不能管理空文件夹。所以你必须写一份自述书。Md保存在一个文件中。否则您将找不到该文件。

3.您本地的项目并不是新的项目。请

git init

Git远程添加origin +“githublink”

转到添加 。

Git commit -m "" go again。

4. 然后git拉origin master(键)

5. 最后git push origin master(解决所有问题)。

http://my.oschina.net/psuyun/blog/123005 reference link

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

您可以直接验证通过