GITHUB推送失败:错误信息为:致命错误:无法访问。

4

在之前,我使用A账户在Android Studio上推代码。现在我注销了并更改为B账户进行推送。当我推送时出现错误:

Push failed: Failed with error: fatal: unable to access 'https://github.com/thangcoder/demo.git/': The requested URL returned error: 403

当我执行推送命令时,出现以下错误:

$ git push -u origin master
remote: Permission to thangcoder/demo.git denied to trangchongcheng.
fatal: unable to access 'https://github.com/thangcoder/demo.git/': The requested URL returned error: 403

请为我提供建议,谢谢。

6个回答

2
我遇到了相同的错误。以下是解决方法。
问题在于你的Git仓库受到SSH密钥的保护。
登录到GitHub > 项目的存储库 > 设置选项卡 > 部署密钥。
删除分配给你的桌面电脑的密钥。
然后再次尝试从Android Studio推送存储库。
有关如何推送存储库的详细信息,请参阅:"如何在Android Studio中使用GitHub"
这对我起作用了!

0

我也曾经遇到过同样的问题,费了好大力气才找到解决方法。

事实上,仔细阅读错误信息是非常有帮助的:

推送失败:失败原因为:无法访问

好吧,这就是问题所在。只需将用户添加为存储库的协作者即可。

https://help.github.com/articles/inviting-collaborators-to-a-personal-repository/

注意:仅将用户添加到组织中是不够的。

0

很明显您没有对该仓库的写入权限。请向thangcoder请求添加您的写入权限。


非常抱歉,但是如何添加写入权限呢 @Ramit - cheng
我猜thangcoder创建了这个仓库,他/她可以给你写入权限。如果这个仓库是由你创建的,请告诉我。 - Ramit

0

0

我曾经遇到过这个问题,请按照以下方式操作:

1.git config --global --unset user.name
2.git config --global --unset user.email
3.git remote add origin https://github.com/username/file.git
4.git push -u origin master

在推送 GitHub 后,会要求用户 B 输入用户名和密码。


0

修改你的文件 .git/config

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://你的github用户名:你的github密码@github.com/Pandaring/Demos.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master

2
感谢您提供这段代码片段,它可能会提供一些有限的、即时的帮助。通过展示为什么这是一个好的解决方案,适当的解释将极大地提高其长期价值,并使其对未来有类似问题的读者更有用。请编辑您的答案,添加一些解释,包括您所做的假设。 - Maximilian Peters

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