我能够通过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
alis@github.com/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://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:\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

当前回答

我其实有一个非常简单的解决方案。我所做的只是在克隆存储库后以不同的方式编辑git配置文件。远程源url是您需要在默认配置文件中编辑的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

其他回答

编辑repo目录下的.git/config文件

查找url=[远程“原点”]部分下的条目

从url更改=https://github.com/rootux/my-repo.git到https://USERNAME@github.com/rootux/my-report.git

其中USERNAME是您的github用户名

我面临着类似的问题,大多数答案在我的情况下都不起作用,我得到了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

它将为您生成代码,输入generated为您的浏览器编码以进行身份验证。

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

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

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

我其实有一个非常简单的解决方案。我所做的只是在克隆存储库后以不同的方式编辑git配置文件。远程源url是您需要在默认配置文件中编辑的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

我面临同样的问题,并注意到我试图推送分支的存储库是私有的。因此,请尝试以下步骤:

确保您可以访问该专用存储库首先分叉存储库。您将注意到存储库URL将包含您的GitHub用户名现在像这样克隆-->git Clonehttps://github.com/your-github-username/example-repository.git在克隆的存储库文件夹-->cd存储库目录中输入

对克隆的存储库做任何想做的事情。保持在同一个克隆存储库目录中进行下一步操作

检查所有分支。这将列出可用的分支-->git分支立即创建分支-->git checkout-b您的分支名称运行gitbranch检查分支是否已创建现在运行命令-->gitadd。提交您的更改-->gitcommit-m“您的消息”推送您的分支-->git推送来源您的分支名称检查GitHub站点,确保您的分支现在被推送

这就是全部

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

通过访问您的git帐户创建回购。

生成ssh密钥:

ssh-keygen -t rsa -C "your_email@example.com"

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

ssh -T git@github.com
clone the repo:
git clone git://github.com/username/your-repository

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

git remote set-url origin git@github.com:username/your-repository.git

现在尝试编辑文件(尝试README),然后执行以下操作:

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

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