尝试从 Git 推送时如何更改 GitHub 帐户?

问题描述 投票:0回答:3

所以我可能已经在一个我以后不会使用的帐户下设置了 Git,我想将该帐户更改为我的个人 GitHub 帐户。我想推下我个人而不是那个。

如果这有任何相关性,我已经为我的计算机创建了一个单独的 SSH 密钥,但由于我没有经验,我不确定如何使用它。

我的最终目标是更改我所在的 GitHub 帐户,因为每当我尝试将代码推送到我个人帐户的存储库时,我都会收到此错误消息:

$ git push origin master
remote: Permission to maiusername/SURVIVAL2.git denied to SupernovaRobotics.
fatal: unable to access 'https://github.com/maiusername/SURVIVAL2.git/': The requested URL returned error: 403

SupernovaRobotics 是我想要摆脱的东西,但我不确定怎么做!

请帮忙!!

java git github push
3个回答
0
投票

将您的公共 ssh 密钥添加到您的 GitHub 帐户(在右上角下拉,设置,SSH 和 GPG 密钥,新的 SSH 密钥)。
然后执行:

git remote set-url origin https://github.com/username/desiredrepo.git

此命令更改 origin.1 的存储库


0
投票

首先,如果您要推送到 https url,则更改有关 SSH 的任何内容都无关紧要。

关于 HTTPS,如果一直使用错误的用户,则意味着 Git 使用了错误的凭据(用户名/密码)。那是因为您必须使用 credential helper 来缓存所述凭据。

检查您使用的凭证助手:

git config -l | grep credential

替代方案(如果您确实更改了 ~/.ssh/id_rsa(.pub) 密钥)是使用 ssh url

git remote set-url origin [email protected]:maiusername/SURVIVAL2.git

然后您的新 ssh 密钥将被考虑在内。


0
投票

你需要:

  • 访问您的 Windows 凭据管理器;
  • 点击“windows's credentical”(我不知道你会怎么看这个,因为我的windows是葡萄牙语的)
  • 寻找“git:https://...”并删除它 所以,当你再次尝试推送时,git 会要求你连接你的 github 帐户,然后你连接到你的新帐户:)
© www.soinside.com 2019 - 2024. All rights reserved.