请求的URL返回错误:403禁止访问github.com。

11

所以,我在另一台机器上设置了一个存储库。我已经提交并推送了文件,并且它们在github.com上显示正常。现在,我在另一台机器上运行了git init,并且正在尝试拉取。

# git remote set-url origin git@github.com: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

请提供更多信息 - 您在该计算机上使用的是哪个git版本?您设置了用户名和密码吗?您是否在防火墙后面或使用代理? - Shmulik Klein
git版本为1.7.1,我没有使用代理,至少我不知道。我不确定是否设置了用户名和密码。 - User
那可能就是你的问题了,使用 git config --global user.name 你的用户名 进行设置,密码也同样如此。 - Shmulik Klein
@ShmulikKlein,user.name与身份验证无关。 - VonC
5个回答

12

你需要检查在成功向GitHub推送时使用的凭据(用户名/密码),并在新的本地仓库中重复使用这些凭据。

特别要检查使用的url类型:ssh (git@github.com:me/someproj.git) 或 https (https://github.com/me/someproj.git)。
还要检查是否在该GitHub账户和仓库上启用了双因素身份验证

你可以将正确的用户名嵌入到你的url中:

cd /path/to/new/local/repo
git remote add origin https://me@github.com/me/someproj.git

2

2
你可以尝试使用命令git remote -v来检查远程代码库的URL是否正确。 如果不正确,你应该尝试
git remote set-url origin repo-url

修复任何打字错误


2

如果您在同一台计算机上使用两个帐户,将会出现此错误。

enter image description here

在 Windows 10 中, 控制面板 -> 用户帐户 -> 管理凭据。 删除 GitHub 帐户即可。


1

对于那些删除凭据或更改URL问题无法解决的人。

我强烈建议检查您是否有权限将内容推送到存储库。 为确保这一点,请请求存储库管理员在存储库设置的“管理访问”部分中授予您写入权限。 希望这对您有用。

the manage access section in github add contributor


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接