如何从工作Github帐户切换到个人帐户?

ql3eal8s  于 2023-06-20  发布在  Git
关注(0)|答案(2)|浏览(266)

我有两个Github账户,一个是个人账户,另一个是工作账户。我正在对我的个人仓库执行一个“命令行”git提交,但它仍然显示“工作”帐户,并向personalaccount/sample.git抛出Permission to personalaccount/sample.git denied。如何将工作帐户切换到个人帐户?

q1qsirdb

q1qsirdb1#

检查您的git config credential.helper配置:如果返回manager,则意味着凭证(用户名/密码)已缓存。
键入git credential-manager reject https://github.com,如explained here
下次推送将再次要求您输入用户名/密码。

p8h8hvxi

p8h8hvxi2#

MacOS -使用gh CLI

安装gh CLI

brew install gh

对于MacOS,您不需要运行git config,因为GCM会自动为您配置Git。
当您需要切换您登录的帐户时

gh auth login

它将询问类似下面内容

? What account do you want to log into? GitHub Enterprise Server
? GHE hostname: github.com
? You're already logged into github.com. Do you want to re-authenticate? Yes
? 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

! First copy your one-time code: XXXX-XXXX
Press Enter to open github.com in your browser...
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as xxxx_xxxx

然后你克隆/或做任何其他git操作如下

gh repo clone project/repo

参考:https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git

相关问题