推送到 Git 返回错误代码 403 fatal:HTTP 请求失败

发布于 2024-12-04 17:32:51 字数 5083 浏览 2 评论 0原文

我能够通过 HTTPS 身份验证克隆此存储库的副本。我已经进行了一些提交,并希望将其推回 GitHub 服务器。在 Windows 7 x64 上使用 Cygwin。

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

还可以将其设置为详细模式。我还是很困惑。

C:\cygwin\home\XPherior\Code\lunch_call>set GIT_CURL_VERBOSE=1

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL connection using AES256-SHA
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
< WWW-Authenticate: Basic realm="GitHub"
<
* Ignoring the response-body
* Expire cleared
* Connection #0 to host github.com left intact
* Issue another request to this URL: 'https://[email protected]/dereker
dmann/lunch_call.git/info/refs?service=git-receive-pack'
* Couldn't find host github.com in the _netrc file; using defaults
* Re-using existing connection! (#0) with host github.com
* Connected to github.com (207.97.227.239) port 443 (#0)
* 0x23cb740 is at send pipe head!
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="GitHub"
* The requested URL returned error: 401
* Closing connection #0
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL re-using session ID
* SSL connection using AES256-SHA
* old SSL session ID is stale, removing
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs HTTP/1.1
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

* The requested URL returned error: 403
* Expire cleared
* Closing connection #0
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

这些是我拥有的 git 和 curl 版本:

C:\Users\XPherior>git --version
git version 1.7.4.msysgit.0

C:\Users\XPherior>curl --version
curl 7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate Largefile NTLM SSL SSPI libz

I was able to clone a copy of this repo over HTTPS authenticated. I've made some commits and want to push back out to the GitHub server. Using Cygwin on Windows 7 x64.

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

Also set it up with verbose mode. I'm still pretty baffled.

C:\cygwin\home\XPherior\Code\lunch_call>set GIT_CURL_VERBOSE=1

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL connection using AES256-SHA
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
< WWW-Authenticate: Basic realm="GitHub"
<
* Ignoring the response-body
* Expire cleared
* Connection #0 to host github.com left intact
* Issue another request to this URL: 'https://[email protected]/dereker
dmann/lunch_call.git/info/refs?service=git-receive-pack'
* Couldn't find host github.com in the _netrc file; using defaults
* Re-using existing connection! (#0) with host github.com
* Connected to github.com (207.97.227.239) port 443 (#0)
* 0x23cb740 is at send pipe head!
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="GitHub"
* The requested URL returned error: 401
* Closing connection #0
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL re-using session ID
* SSL connection using AES256-SHA
* old SSL session ID is stale, removing
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs HTTP/1.1
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

* The requested URL returned error: 403
* Expire cleared
* Closing connection #0
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

These are the versions of git and curl that I have:

C:\Users\XPherior>git --version
git version 1.7.4.msysgit.0

C:\Users\XPherior>curl --version
curl 7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate Largefile NTLM SSL SSPI libz

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

小…红帽 2024-12-11 17:32:52

肖恩的回答的一点补充。

您可以使用 git remote set-url 命令,而不是手动编辑 .git/config 文件。

在你的情况下,它应该是:

git remote set-url origin ssh://[email protected]/derekerdmann/lunch_call.git

我发现它比乱搞点文件更容易和更干净。

One small addition to Sean's answer.

Instead of editing .git/config file manually, you can use git remote set-url command.

In your case it should be:

git remote set-url origin ssh://[email protected]/derekerdmann/lunch_call.git

I find it easier and cleaner, than messing around with dot-files.

香橙ぽ 2024-12-11 17:32:52

编辑存储库目录下的 .git/config 文件

[remote "origin"] 部分下查找 url= 条目

将其从 url 更改=https://github.com/rootux/my-repo.git
https://[电子邮件受保护]/rootux/my- repo.git

其中 USERNAME 是你的 github 用户名

Edit .git/config file under your repo directory

Find url= entry under section [remote "origin"]

Change it from url=https://github.com/rootux/my-repo.git to
https://[email protected]/rootux/my-repo.git

where USERNAME is your github user name

深居我梦 2024-12-11 17:32:52

其他建议切换到 SSH 的答案有点没有抓住重点。支持 HTTPS,但您必须使用 GITHUB 密码登录,而不是 SSH 密码(这正是给我带来同样错误的原因)。

我遇到了同样的问题,但确保在终端密码提示符处使用我的实际 GitHub 密码修复了解决方案,无需更改配置或诉诸 SSH。

值得注意的是,许多公共机构(例如我的学校)会阻止 SSH,但允许 HTTPS(这是我首先开始通过 HTTPS 进行克隆的唯一原因)。

希望能帮助其他遇到同样问题的人...

The other answers that suggest switching to SSH sort of miss the point. HTTPS is supported, but you must log in with you GITHUB password, not your SSH passphrase (which was what was giving me the same exact error).

I was having the same problem, but making sure to use my actual GitHub password at the terminal password prompt fixed the solution with no alteration to the config, or resorting to SSH.

The reason it is important to note this, is many public institutions (such as my school) will block SSH, but allow HTTPS (which is the only reason I started cloning over HTTPS in the first place).

Hope that helps anyone else having the same issue...

眼睛会笑 2024-12-11 17:32:52

如果您使用的是 Windows,有时可能会发生这种情况,因为 Windows 将外部存储库(在我们的示例中为 github)的凭据存储在其自己的存储中。那里保存的凭据可能与您现在需要的凭据不同。

输入图像描述这里

因此,为了避免这个问题,只需在这个存储中找到 github 并删除保存的凭据即可。此后,在推送时 git 将请求您的凭据并允许您推送。

If you are using windows, sometimes this may happen because Windows stores credentials for outer repo (in our case github) in its own storage. And credentials that saved there can be different from those you need right now.

enter image description here

So to avoid this problem, just find github in this storage and delete saved credentials. After this, while pushing git will request your credentials and will allow you to push.

橙味迷妹 2024-12-11 17:32:52

Mac OS X 上出现同样的错误和解决方案。

一切都工作正常,直到我在 GitHub 上创建新帐户并尝试推送

$ git push -u origin master

并收到错误:

远程:权限NEWUSER/NEWREPO.git 被 OLDUSER 拒绝。致命:无法访问 'https://github.com/NEWUSER/NEWREPO.git/ ': 请求的 URL 返回错误:403

它应该通过为全局或当前存储库设置 user.name 来修复,

$ git config –-global user.name NEWUSER
$ git config user.name NEWUSER

但事实并非如此。

我通过从“密码”部分下的“钥匙串访问”应用中删除与 GitHub 关联的 OLDUSER 来修复此问题。然后push命令就成功了。

$ git push -u origin master

参考

Same error and resolution on Mac OS X.

Everything was working fine till I created a new account on GitHub and tried to push

$ git push -u origin master

And got the error:

remote: Permission to NEWUSER/NEWREPO.git denied to OLDUSER. fatal: unable to access ‘https://github.com/NEWUSER/NEWREPO.git/': The requested URL returned error: 403

It should have fixed by setting the user.name either for global or current repo

$ git config –-global user.name NEWUSER
$ git config user.name NEWUSER

But it didn’t.

I got it fixed by deleting the OLDUSER associated with GitHub from Keychain Access app under Passwords section. Then the push command went successful.

$ git push -u origin master

reference

随风而去 2024-12-11 17:32:52

这对我有用 -:

git remote set-url origin https://[email protected]/user/repo.git

希望有帮助

This works for me -:

git remote set-url origin https://[email protected]/user/repo.git

Hope it helps

掩于岁月 2024-12-11 17:32:52

这里有很多答案,但这就是解决我的问题的方法。

自 2020 年 7 月起,您必须使用

所以你必须 在您的个人资料设置页面中生成访问令牌并将其用作您的密码。选中写入存储库所需的框。

现在使用以下命令将您的用户名添加到存储库:

git remote set-url origin https://[email protected]/user/repo.git

当您尝试推送时,它会询问您的密码。 输入您新生成的令牌。

如果您在推送时仍然遇到问题,请使用网络界面将其分叉为个人存储库,以隔离任何权限问题。您将能够专注于解决身份验证问题。

A lot of answers here, but this is what solved my problem.

Since July 2020 you must use Token authentication to access GitHub if you are using HTTPS.

So you must generate an access token in your profile settings page and use it as your password. Check the boxes necessary to write to the repository.

Now add your username to the repo with this command:

git remote set-url origin https://[email protected]/user/repo.git

When you try to push, it will ask for your password. Enter your newly generated token.

If you are still having trouble pushing, use the web interface to fork it as a personal repo to isolate any permission problem. You'll be able to focus on solving the auth problem.

潦草背影 2024-12-11 17:32:52

我认为@deepwaters 对于旧版本的答案是正确的。 HTTPS URL 需要有用户名。我有 git 1.7.0.4 并且 git push origin master 甚至不会要求输入密码,直到我添加它。

I think @deepwaters got the answer correct for older versions. The HTTPS URL needs to have the username. I had git 1.7.0.4 and git push origin master wouldn't even ask for a password till I added it.

橘和柠 2024-12-11 17:32:52

403 代码是“禁止”。服务器看到您的请求并拒绝了它。您是否有权推送到该存储库?

A 403 code is "Forbidden". The server saw your request and refused it. Do you have permission to push to that repository?

浮生面具三千个 2024-12-11 17:32:52

想通了。我通过 HTTPS 克隆。设置我的公共 SSH 密钥、通过 SSH 克隆以及通过 SSH 推送修复了该问题。

Figured it out. I cloned over HTTPS. Setting up my public SSH keys, cloning over SSH, and pushing over SSH fixed it.

别忘他 2024-12-11 17:32:52

执行此操作以进行临时修复

git push -u https://username:[email  ;受保护]/用户名/repo_name.git大师

Do this for a temporary fix

git push -u https://username:[email protected]/username/repo_name.git master

挥剑断情 2024-12-11 17:32:52

我遇到了同样的错误,原因很愚蠢 - 我没有权限提交到选定的存储库。我不知道我必须

  1. 分叉选定的项目,首先
  2. 在本地克隆存储库,在
  3. 本地提交我的更改
  4. ,将更改推送到我的 github 克隆
  5. 请求,将请求拉取到上游,

https://help.github.com/categories/63/articles

I faced the same error and the cause was stupid - I did not have privileges to commit to selected repository. I did not know that I have to

  1. fork selected project first
  2. clone repository locally
  3. commit my changes locally
  4. push changes to my github clone
  5. request pull request to upstream

as described in https://help.github.com/categories/63/articles

辞别 2024-12-11 17:32:52

实际上我对此有一个非常简单的解决方法。我所做的只是在克隆存储库后以不同的方式编辑 git 配置文件。远程源 URL 是您需要在默认 config 文件中编辑的内容。它应该如下所示

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://*username*@github.com/*username*/*repository*.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

I actually had a very simple fix to this. All i did was edit the git config file differently after cloning the repository. The remote origin url is what you need to edit in your default config file. It should look like seen below

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://*username*@github.com/*username*/*repository*.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
赤濁 2024-12-11 17:32:52
  1. 单击您的存储库
  2. 在右侧,单击“设置”
  3. 在左侧选项面板上,单击“协作者”
  4. 添加您在 GitHub 中认识的人名
  5. 单击“添加协作者”

在此之后,我们的“推送到 Git”开始工作美好的。

  1. Click on your repository
  2. On the right hand side, click on "Settings"
  3. On the left hand side option panel, click on "Collaborators"
  4. Add the person name you know in GitHub
  5. Click "Add Collaborators"

After this our "Push to Git" worked fine.

但可醉心 2024-12-11 17:32:52

将其从 更改

url=https://[email protected]/derekerdmann/lunch_call.git 

url=ssh://[email protected]/derekerdmann/lunch_call.git

它有效!

不要忘记“@”之前的“git”。

change it from

url=https://[email protected]/derekerdmann/lunch_call.git 

to

url=ssh://[email protected]/derekerdmann/lunch_call.git

It works!

Do not forget the "git" before the "@".

淡笑忘祈一世凡恋 2024-12-11 17:32:52

下面是解决方案

对于 Windows,您可以在此处找到按键:

控制面板 >用户帐户>凭证管理器> Windows 凭据 >通用凭据

接下来,删除 Github 密钥。

在 Mac 中

1-在 Finder 中,搜索“钥匙串访问”应用。

2在“钥匙串访问”中,搜索 github.com。

3-找到 github.com 的“互联网密码”条目。

4-相应地编辑或删除条目。

Below is the solution

For Windows you can find the keys here:

control panel > user accounts > credential manager > Windows credentials > Generic credentials

Next, remove the Github keys.

In mac

1-In Finder, search for the Keychain Access app.

2In Keychain Access, search for github.com.

3-Find the "internet password" entry for github.com.

4-Edit or delete the entry accordingly.

淡淡的优雅 2024-12-11 17:32:52

对于那些在使用ssh时遇到权限被拒绝403错误的人(根据Xiao) 或 http 网址
尝试这些命令

>git config --global --unset-all credential.helper

>git config --unset-all credential.helper

使用管理员权限

>git config --system --unset-all credential.helper

For those having permission denied 403 error while using ssh(according to Xiao) or http urls
try these commands

>git config --global --unset-all credential.helper

>git config --unset-all credential.helper

with administrator rights

>git config --system --unset-all credential.helper
み格子的夏天 2024-12-11 17:32:52

上述答案均不适用于我的企业 GitHub 帐户。按照以下步骤通过 ssh 密钥生成方式进行推送。

通过访问您的 git 帐户创建一个存储库。

生成 ssh 密钥:

ssh-keygen -t rsa -C "[email protected]"

将文件 ~/.ssh/id_rsa.pub 的内容复制到 GitHub 帐户设置中的 SSH 密钥。
测试 SSH 密钥:

ssh -T [email protected]
clone the repo:
git clone git://github.com/username/your-repository

现在 cd 到您的 git 克隆文件夹并执行:

git remote set-url origin [email protected]:username/your-repository.git

现在尝试编辑文件(尝试自述文件),然后执行:

git add -A
git commit -am "my update msg"
git push -u origin master

更新:新的 git 版本似乎建议在创建新存储库时不要有任何文件。因此创建一个空白仓库。

None of the above answers worked for my enterprise GitHub account. Follow these steps for pushing via ssh key generation way.

Create a repo by visiting your git account.

Generate ssh key:

ssh-keygen -t rsa -C "[email protected]"

Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your GitHub account settings.
Test SSH key:

ssh -T [email protected]
clone the repo:
git clone git://github.com/username/your-repository

Now cd to your git clone folder and do:

git remote set-url origin [email protected]:username/your-repository.git

Now try editing a file (try the README) and then do:

git add -A
git commit -am "my update msg"
git push -u origin master

Update: new git version seems to recommend not to have any file while new repo is created. Hence make aa blank repo.

风蛊 2024-12-11 17:32:52

如果您在 github 上遇到 403 错误,

请务必在创建令牌时选中所有复选框:

https://github.com/settings/令牌

我认为 github 令牌生成页面有设计缺陷。

if you get 403 error with github,

sure to check all checkboxs when create token:

https://github.com/settings/tokens

i think github token generate page has design flaw.

森林迷了鹿 2024-12-11 17:32:52

我遇到了类似的问题,大多数答案在我的情况下不起作用,我收到了权限被拒绝 403 禁止错误。以下步骤帮助我解决了问题:

如果安装了brew,请通过以下命令安装git CLI:

brew install gh

参考安装git CLI https://github.com/cli/cli#installation

然后运行

gh auth login  

它会问你以下问题,回答如下,

What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

它会为你生成代码,输入生成的代码在浏览器中进行身份验证。

! First copy your one-time code: 14*B-E2*7

Press Enter to open github.com in your browser... 
✓ Authentication complete.

通过执行上述步骤,您将能够将代码推送到您的存储库。

I faced similar issue and most of the answer did not work in my case, i was getting permission denied 403 forbidden error. Following steps helped me to resolve the issue:

Install git CLI by below command if you have brew installed:

brew install gh

Reference to install git CLI https://github.com/cli/cli#installation

then run

gh auth login  

it will ask you following questions, answer like this,

What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

It will generate code for you, enter generated to code your browser for authentication.

! First copy your one-time code: 14*B-E2*7

Press Enter to open github.com in your browser... 
✓ Authentication complete.

By following above steps you will be able to push code to your repository.

山田美奈子 2024-12-11 17:32:52

对我有用的:

我的存储库是一个分叉,并且仍然链接到父存储库。

git remote -v

会告诉你这是否是你的回购协议。

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

允许您将其重新配置到您的存储库,然后允许您推送。

What worked for me:

My repo was a fork and still linked to the the parents repo.

git remote -v

Will tell you if it is your repo or not.

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

Allows you to reconfigure it to your repo and then allow you to push.

小忆控 2024-12-11 17:32:52

如果由于某种原因不允许 SSH,HTTPS 也可以

要通过HTTPS推送提交,您应该使用个人访问令牌 并确保读写在定义的范围中可用个人令牌的访问权限。

在GitHub中设置如下。

输入图片此处描述

If SSH is not allowed for some reason, HTTPS is also ok.

To push the commits by HTTPS, you should use the personal access token and make sure the read and write is available in Scopes which define the access for personal tokens.

Setting in GitHub as follows.

enter image description here

和我恋爱吧 2024-12-11 17:32:52

对于任何好奇的人,我的 mac 机器与 lucid vm 运行 git 1.7.6 与 1.7.0.4,并且可以从我的 mac(较新的 git)推送完全相同的存储库,但不能从 VM

相同的curl 版本。也许某些较旧的 git 版本不支持 https 推送?

For anyone curious, my mac machine vs lucid vm ran git 1.7.6 vs 1.7.0.4, and the exact same repo was pushable from my mac (newer git) but not the VM

Same curl version. Perhaps some older git versions don't support https pushes?

緦唸λ蓇 2024-12-11 17:32:52

添加用户名作为 URL 的一部分,发生此错误是因为 git 命令点击的是 http 而不是 https。因此设置 url

git remote set-url origin https://<username>@github.com/Path_to_repo.git

之后系统将提示您输入密码:

Add the user name as part of the URL and This error happens because the git command is hitting http instead of https. So set the url

git remote set-url origin https://<username>@github.com/Path_to_repo.git

After which you will be prompted for password:

云归处 2024-12-11 17:32:52

使用管理员权限尝试以下命令。这个命令解决了我的问题。希望它能解决您的问题。

git config --system --unset-all credential.helper

Try below command using administrator permission. This command solved my issue. Hope it will resolve your problem.

git config --system --unset-all credential.helper
别挽留 2024-12-11 17:32:52

我想出了这个问题的我自己的变体。

问题不是将协议从 https 更改为 ssl,而是,
设置 Github 全局用户名和电子邮件! (我试图推动
私人存储库。

git config --global user.email "[email protected]"

git config --global user.name "Your full name"

I figured out my own variation of this problem.

The issue was not changing the protocol from https to ssl, but instead,
setting the Github global username and email! (I was trying to push to a
private repository.

git config --global user.email "[email protected]"

git config --global user.name "Your full name"
愿得七秒忆 2024-12-11 17:32:51

我刚刚遇到了同样的问题,并找出原因。

Github似乎只支持ssh方式读写repo,尽管https方式也显示“Read&Write”。

因此,您需要将 PC 上的存储库配置更改为 ssh 方式:

  1. 编辑存储库目录下的 .git/config 文件。
  2. [remote "origin"] 部分下查找url=条目。
  3. 将其更改为:
    url=https://[电子邮件受保护]/derekerdmann/lunch_call.git
    至:
    url=ssh://[电子邮件受保护]/derekerdmann/ Lunch_call.git
    即,将@符号之前的所有文本更改为ssh://git
  4. 保存config文件并退出。现在您可以使用 git push origin master 来同步 GitHub 上的存储库。

I just got the same problem and just figured out what's cause.

Github seems only supports ssh way to read&write the repo, although https way also displayed 'Read&Write'.

So you need to change your repo config on your PC to ssh way:

  1. Edit .git/config file under your repo directory.
  2. Find url=entry under section [remote "origin"].
  3. Change it from:
    url=https://[email protected]/derekerdmann/lunch_call.git
    to:
    url=ssh://[email protected]/derekerdmann/lunch_call.git
    That is, change all the texts before @ symbol to ssh://git
  4. Save config file and quit. now you could use git push origin master to sync your repo on GitHub.
吃不饱 2024-12-11 17:32:51

为了确保能够使用 https 协议登录,您应该首先将您的身份验证凭据设置为 git 远程 URI

git remote set-url origin https://[email protected]/user/repo.git

然后系统会询问您尝试 git push 时需要密码。

其实这是关于http认证格式的。你也可以设置一个密码:

https://youruser:[email protected]/user/repo.git

你应该知道,如果你这样做,你的 github 密码将以明文形式存储在你的 .git 目录中,这显然是不可取的。

To definitely be able to login using https protocol, you should first set your authentication credential to the git Remote URI:

git remote set-url origin https://[email protected]/user/repo.git

Then you'll be asked for a password when trying to git push.

In fact, this is on the http authentication format. You could set a password too:

https://youruser:[email protected]/user/repo.git

You should be aware that if you do this, your github password will be stored in plaintext in your .git directory, which is obviously undesirable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文