git 请求的 URL 返回错误:403 Forbidden while accessing github.com

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37982046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:17:41  来源:igfitidea点击:

The requested URL returned error: 403 Forbidden while accessing github.com

gitgithub

提问by User

So, I have a repo setup, on another machine. I've committed and pushed files and they view fine on github.com. Now, I have ran git initon another machine and I'm trying to pull.

所以,我在另一台机器上有一个 repo 设置。我已经提交并推送了文件,它们在 github.com 上显示良好。现在,我git init在另一台机器上跑了,我想拉。

# git remote set-url origin [email protected]:me/someproj.git
fatal: No such remote 'origin'

# git remote add origin https://github.com/me/someproj.git

# git pull
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/me/someproj.git/info/refs

fatal: HTTP request failed

# git remote -v
origin  https://github.com/me/someproj.git (fetch)
origin  https://github.com/me/someproj.git (push)

# git pull origin
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/me/someproj.git/info/refs

fatal: HTTP request failed

回答by VonC

You need to check what credential (username/password) you are using on the machine where a push to GitHub succeed, and re-use those credential in your new local repo.

您需要检查您在成功推送到 GitHub 的机器上使用的凭据(用户名/密码),并在新的本地存储库中重新使用这些凭据。

Check especially the type of url used: ssh ([email protected]:me/someproj.git) or https (https://github.com/me/someproj.git).
Check also if you were using 2FA (Two-Factor Authentication)or not for that GitHub account and repos.

尤其要检查所使用的 url 类型:ssh ( [email protected]:me/someproj.git) 或 https ( https://github.com/me/someproj.git)。
还要检查您是否为该 GitHub 帐户和存储库使用了 2FA(双因素身份验证)

You can embed the right username in your url::

您可以在您的网址中嵌入正确的用户名::

cd /path/to/new/local/repo
git remote add origin https://[email protected]/me/someproj.git

回答by Shmulik Klein

When trying to access https://github.com/me/someproj.git/info/refsfrom the browser you'll notice the following message which associated with a 403 status code:

当尝试从浏览器访问https://github.com/me/someproj.git/info/refs 时,您会注意到以下与 403 状态代码相关的消息:

Please upgrade your git client. GitHub.com no longer supports git over dumb-http: https://github.com/blog/809-git-dumb-http-transport-to-be-turned-off-in-90-days

请升级您的 git 客户端。GitHub.com 不再通过哑 http 支持 git:https: //github.com/blog/809-git-dumb-http-transport-to-be-turned-off-in-90-days

If you are using git prior to 1.6.6, try to update it or better use a SSH protocol.

如果您使用 1.6.6 之前的 git,请尝试更新它或更好地使用 SSH 协议。

Also check your setup with git config --global user.nameand git config --global user.password.

还可以使用git config --global user.name和 来检查您的设置git config --global user.password

回答by dstrants

You can try the git remote -vcommand to check the remote repo URL is ok. If it is not, you should try

您可以尝试使用该git remote -v命令检查远程仓库 URL 是否正常。如果不是,你应该尝试

git remote set-url origin repo-url

To fix any typos

修正任何错别字