git - Git Push返回Error Code 403致命错误: HTTP request failed

  显示原文与译文双语对照的内容

我可以通过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

时间:

我得到了同样的问题,只是找出原因。

库托管似乎也只支持ssh方式来read&写的回购,虽然https的方式显示'read&写入'。

因此,你需要将你的计算机上的仓库配置更改为ssh方式:

  1. 在你的仓库目录下编辑 .git/config 文件
  2. 下找到 url= 条目部分 [remote"origin"]
  3. 更改自 url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.giturl=ssh://git@github.com/derekerdmann/lunch_call.git 即,在 @ 符号到 ssh://git 之前更改所有文本
  4. 保存 config 文件并退出。 现在你可以使用 git push origin master 在GitHub上同步你的仓库

要想使用 https 协议登录,你应该首先将你的认证凭证设置为的远程 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 目录中,这显然是不需要的。

Seans的一个小问题。

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

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


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

我发现比dot-files更容易和更干净。

在你的仓库目录下编辑 .git/config 文件

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

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

USERNAME 是你的github用户名

我认为 @deepwaters 对旧版本的答案正确。 HTTPS URL需要有用户名。 我有 git 1.7.0.4 和 git push origin master 在我添加密码之前,甚至不会要求密码。

...