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

我能够通过HTTPS身份验证克隆此回购的副本。 我做了一些提交并希望推回到GitHub服务器。 在Windows 7 x64上使用Cygwin。

C:cygwinhomeXPheriorCodelunch_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

还要用详细模式进行设置。 我仍然很困惑。

C:cygwinhomeXPheriorCodelunch_call>set GIT_CURL_VERBOSE=1

C:cygwinhomeXPheriorCodelunch_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

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

C:UsersXPherior>git --version
git version 1.7.4.msysgit.0

C:UsersXPherior>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

我刚刚得到同样的问题,只知道是什么原因。

Github似乎只支持SSH方式来读取和写入回购,虽然HTTPS方式也显示'读取和写入'。

所以你需要改变你的PC上的repo配置为ssh方式:

  • 在您的repo目录下编辑.git/config文件
  • [remote "origin"]部分找到url= entry
  • 将其从url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.giturl=ssh://git@github.com/derekerdmann/lunch_call.git 。 即将@符号前的所有文本更改为ssh://git
  • 保存config文件并退出。 现在你可以使用git push origin master在GitHub上同步你的repo

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

    git remote set-url origin https://yourusername@github.com/user/repo.git
    

    然后,当您尝试按git push时,您会被要求输入密码。

    实际上,这是使用http认证格式。 你也可以设置密码:

    https://youruser:password@github.com/user/repo.git
    

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


    肖恩的答案是一个小的补充。

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

    你的情况应该是:

    git remote set-url origin ssh://git@github.com/derekerdmann/lunch_call.git
    

    我发现它更容易和更清洁,而不是乱七八糟的文件。

  • help.github.com:更改远程的URL
  • 链接地址: http://www.djcxy.com/p/8635.html

    上一篇: Pushing to Git returning Error Code 403 fatal: HTTP request failed

    下一篇: How to push different local Git branches to Heroku/master