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

Mik*_*ike 608 git dvcs github

我能够通过HTTPS身份验证克隆此repo的副本.我做了一些提交,想要推回到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
alis@github.com/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)

同时使用详细模式进行设置.我还是很困惑.

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://MichaelDrogalis@github.com/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
alis@github.com/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)

这些是我拥有的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
Run Code Online (Sandbox Code Playgroud)

Xia*_*iao 817

我刚刚遇到同样的问题,只是弄明白是什么原因.

Github似乎只支持ssh方式来读取和写入repo,虽然https方式也显示"Read&Write".

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

  1. 编辑.git/configrepo目录下的文件
  2. 找到url=条目下的条目[remote "origin"]
  3. 将它url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.git改为 url=ssh://git@github.com/derekerdmann/lunch_call.git.也就是说,将@符号前的所有文本更改为ssh://git
  4. 保存config文件并退出.现在你可以用来git push origin master在GitHub上同步你的回购

  • 当您使用git只读地址(这是您未登录时的默认地址)而不是读取+写入ssh地址进行克隆时,通常会遇到此问题. (52认同)
  • 对于那些寻找非ssh解决方案的人,请在此处查看其他一些答案.将您的用户名添加到https网址似乎有效.(更改配置URL,以便https:// @ github.com/...是https://UNAME@github.com/...) (42认同)
  • 我的`.git/config`更像是`url = https:// github.com/mynickname/my_repo.git`但我也把它改成了`url = ssh://git@github.com/mynickname/my_repo. git`它完成了这个伎俩 (41认同)
  • 您可以使用`git remote set-url`命令更改repo url.请参阅下面的答案. (12认同)
  • 或者只需使用`git remote set-url <name> git@github.com:<username>/<repo> .git从命令行更改它 (7认同)
  • 对不起,这是一个创可贴解决方案.SSH不是每个人的选择.Github确实支持HTTPS.你说Github说HTTPS支持读/写但不知道它实际上不支持它吗?我认为这不是这种情况.相反,我们将使用SSH并忽略该问题,而不是找出HTTPS连接的错误. (5认同)

Thi*_*edo 413

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

git remote set-url origin https://yourusername@github.com/user/repo.git
Run Code Online (Sandbox Code Playgroud)

然后在尝试时会要求您输入密码git push.

实际上,这是http身份验证格式.您也可以设置密码:

https://youruser:password@github.com/user/repo.git
Run Code Online (Sandbox Code Playgroud)

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

  • 这应该是公认的答案.没有理由在有命令行界面时手动编辑配置文件. (29认同)
  • SSH在工作时被阻止,所以我必须使用HTTPS.添加用户名可修复我的问题. (12认同)
  • 另外,对我来说,这种方式(https:// username @ github ...)要求输入密码并且工作正常,而ssh:// git @ github ...失败期待公钥认证. (4认同)
  • 请注意,如果您遇到此问题,如果用户名或密码中有特殊字符,则需要对它们进行 URL 编码。例如,@ 需要为 %40。 (4认同)
  • @Achint它是一种身份验证格式.您可以设置密码`https:// youruser:password @ github.com/user/repo.git`尽管[不安全](http://stackoverflow.com/a/5343146/667927) (3认同)

fet*_*tsh 110

肖恩答案的一小部分补充.

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

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

git remote set-url origin ssh://git@github.com/derekerdmann/lunch_call.git
Run Code Online (Sandbox Code Playgroud)

我发现它比使用点文件更容易,更干净.


Gal*_*cha 53

编辑.git/configrepo目录下的文件

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

从更改url=https://github.com/rootux/ms-Dropdown.githttps://USERNAME@github.com/rootux/ms-Dropdown.git

USERNAME你的github用户名在哪里


BMB*_*BMB 43

其他建议切换到SSH的答案忽略了这一点.支持HTTPS,但您必须使用GITHUB密码登录,而不是SSH密码(这就是给出了同样错误的错误).

我遇到了同样的问题,但确保在终端密码提示下使用我的实际GitHub密码修复了解决方案,没有对配置进行任何更改,也没有使用SSH.

重要的是要注意这一点,许多公共机构(例如我的学校)将阻止SSH,但允许HTTPS(这是我首先开始通过HTTPS克隆的唯一原因).

希望能帮助其他人解决同样的问题......


zee*_*wan 25

Mac OS X上的错误和分辨率相同.

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

$ git push -u origin master
Run Code Online (Sandbox Code Playgroud)

得到了错误:

remote:对OLDUSER拒绝的NEWUSER/NEWREPO.git的许可.致命:无法访问' https://github.com/NEWUSER/NEWREPO.git/ ':请求的网址返回错误:403

它应该通过为全局或当前repo设置user.name来修复

$ git config –-global user.name NEWUSER
$ git config user.name NEWUSER
Run Code Online (Sandbox Code Playgroud)

但事实并非如此.

我通过从密码链接部分下的Keychain Access应用程序中删除与GitHub相关联的OLDUSER来解决此问题.然后push命令成功.

$ git push -u origin master
Run Code Online (Sandbox Code Playgroud)

参考


nev*_*ves 20

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

自 2020 年 7 月起,如果您使用 HTTPS,则必须使用Token 身份验证来访问 GitHub 。

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

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

git remote set-url origin https://yourusername@github.com/user/repo.git
Run Code Online (Sandbox Code Playgroud)

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

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


nis*_*sah 17

我认为@dewwaters对旧版本的答案是正确的.HTTPS URL需要具有用户名.我有git 1.7.0.4,git push origin master甚至在我添加之前都不会要求输入密码.


小智 16

这对我有用 - :

git remote set-url origin https://username@github.com/user/repo.git
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你


And*_*ans 14

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

在此输入图像描述

因此,要避免此问题,只需在此存储中找到github并删除已保存的凭据.在此之后,推送git将请求您的凭据,并允许您推送.

  • “您可能需要检查 Windows 凭据管理器并删除`控制面板 &gt; 用户帐户 &gt; 凭据管理器 &gt; Windows 凭据 &gt; 通用凭据`下的 github 条目”详细信息来自此帖子:/sf/answers/2621534681/ (2认同)

Nic*_*eys 10

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


x0v*_*x0v 10

这样做是为了临时修复

git push -u https://username:password@github.com/username/repo_name.git master


lar*_*ech 9

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

[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
Run Code Online (Sandbox Code Playgroud)


Mik*_*ike 7

弄清楚了.我克隆了HTTPS.设置我的公共SSH密钥,通过SSH克隆,并通过SSH修复它.


小智 7

  1. 单击您的存储库
  2. 在右侧,单击"设置"
  3. 在左侧选项面板上,单击"协作者"
  4. 在GitHub中添加您知道的人名
  5. 点击"添加协作者"

在此之后,我们的"推送到Git"工作得很好.


Kap*_*oni 7

下面是解决方案

对于 Windows,您可以在此处找到密钥:

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

接下来,删除 Github 密钥。

在苹果机上

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

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

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

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


Moo*_*och 6

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

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

>git config --unset-all credential.helper
Run Code Online (Sandbox Code Playgroud)

有管理员权限

>git config --system --unset-all credential.helper
Run Code Online (Sandbox Code Playgroud)


cha*_*esh 6

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

通过访问您的 git 帐户创建一个 repo。

生成 ssh 密钥:

ssh-keygen -t rsa -C "your_email@example.com"
Run Code Online (Sandbox Code Playgroud)

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

ssh -T git@github.com
clone the repo:
git clone git://github.com/username/your-repository
Run Code Online (Sandbox Code Playgroud)

现在 cd 到您的 git clone 文件夹并执行以下操作:

git remote set-url origin git@github.com:username/your-repository.git
Run Code Online (Sandbox Code Playgroud)

现在尝试编辑一个文件(尝试 README),然后执行:

git add -A
git commit -am "my update msg"
git push -u origin master
Run Code Online (Sandbox Code Playgroud)

更新:新的 git 版本似乎建议在创建新 repo 时不要有任何文件。因此制作一个空白回购。


Jim*_*ong 5

改变它

url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.git 
Run Code Online (Sandbox Code Playgroud)

url=ssh://git@github.com/derekerdmann/lunch_call.git
Run Code Online (Sandbox Code Playgroud)

有用!

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


Leo*_*rak 5

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

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

https://help.github.com/categories/63/articles中所述

  • 这并不愚蠢,对于大多数公共存储库的首次贡献者来说,这是正确的答案。 (2认同)
  • 多谢。是公共存储库的首次贡献者。这是我的问题 (2认同)

sai*_*009 5

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

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

https://github.com/settings/tokens

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