我有两个Github账户,一个是个人账户,另一个是工作账户。我正在对我的个人仓库执行一个“命令行”git提交,但它仍然显示“工作”帐户,并向personalaccount/sample.git抛出Permission to personalaccount/sample.git denied。如何将工作帐户切换到个人帐户?
? 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
2条答案
按热度按时间q1qsirdb1#
检查您的
git config credential.helper
配置:如果返回manager,则意味着凭证(用户名/密码)已缓存。键入
git credential-manager reject https://github.com
,如explained here。下次推送将再次要求您输入用户名/密码。
p8h8hvxi2#
MacOS -使用gh CLI
安装gh CLI
对于MacOS,您不需要运行git config,因为GCM会自动为您配置Git。
当您需要切换您登录的帐户时
它将询问类似下面内容
然后你克隆/或做任何其他git操作如下
参考:https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git