致命:当前分支 master 没有上游分支 [英] fatal: The current branch master has no upstream branch

查看:30
本文介绍了致命:当前分支 master 没有上游分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的一个项目推送到 github,但我不断收到此错误:

I'm trying to push one of my projects to github, and I keep getting this error:

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

所以我试了一下,得到了这个:

So I tried it and got this:

peeplesoft@jane3:~/846156 (master) $ git push --set-upstream origin master

fatal: Authentication failed

另一个 stackoverflow 线程建议我尝试以下操作,但结果令人失望.

Another stackoverflow thread suggested I try the following, with disappointing results.

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 -u origin mastergit push -u origin --all),您现在需要解决身份验证问题.

You fixed the push, but, independently of that push issue (which I explained in "Why do I need to explicitly push a new branch?": git push -u origin master or git push -u origin --all), you need now to resolve the authentication issue.

这取决于你的 url(ssh 如在 'git@github.com/yourRepo 中,或 https 如在 https://github.com/You/YourRepo)

That depends on your url (ssh as in 'git@github.com/yourRepo, or https as in https://github.com/You/YourRepo)

对于 https 网址:

For https url:

如果您的帐户受到双因素身份验证的保护,您的常规密码不起作用(对于 https url),如此处所述 或此处.

If your account is protected by the two-factor authentication, your regular password won't work (for https url), as explained here or here.

如果您的密码包含特殊字符,同样的问题(如这个答案)

Same problem if your password contains special character (as in this answer)

如果https不行(因为不想生成二级密钥,一个PAT:personal Access Token),那么可以切换到ssh,正如我在此处展示的.

If https doesn't work (because you don't want to generate a secondary key, a PAT: personal Access Token), then you can switch to ssh, as I have shown here.

正如评论中 qwerty 所指出的,您可以使用以下命令在遥控器上自动创建同名分支:

As noted by qwerty in the comments, you can automatically create the branch of same name on the remote with:

git push -u origin head 

为什么?

  • HEAD(请参阅您的 .gitHEAD 文件)具有当前检出分支的 refspec(例如:ref: refs/heads/master)
  • 默认的推送策略是<强>简单
  • HEAD (see your .gitHEAD file) has the refspec of the currently checked out branch (for example: ref: refs/heads/master)
  • the default push policy is simple

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

Since the refpec used for this push is head: (no destination), a missing :<dst> means to update the same ref as the <src> (head, which is a branch).

如果 HEAD 已分离,这将不起作用.

That won't work if HEAD is detached though.

这篇关于致命:当前分支 master 没有上游分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆