
gitSwitchAccount
起因是本地git存在多个账号,提交时显示登录的是lthero-g,我需要切换回lthero-big
lthero@LtherodeMac-mini HiFi-Mark % git push
remote: Permission to lthero-big/HiFi-Mark.git denied to Lthero-g.
fatal: unable to access 'https://github.com/lthero-big/HiFi-Mark/': The requested URL returned error: 403These should reflect the lthero-big account. If not, update them:
git config user.name "lthero-big"
git config user.email "email-associated-with-lthero-big"Update Remote URL to Include lthero-big Credentials Modify the repository’s remote URL to explicitly include the lthero-big username:
git remote set-url origin https://lthero-big@github.com/lthero-big/HiFi-Mark.gitThis forces Git to authenticate as lthero-big. When you push, Git will prompt for the password or use a stored token.
Clear Cached Credentials Your system may have cached Lthero-g credentials. Clear them:
- On macOS Then enter: Press Enter twice to clear the cached credentials.
git credential-osxkeychain erasehost=github.com
protocol=https- Alternatively, open Keychain Access, search for github.com, and delete entries related to Lthero-g.
H Key (recommended for frequent use):
- Generate an SSH key for lthero-big if not already set up: Save it (e.g., ~/.ssh/id_ed25519_lthero_big).
ssh-keygen -t ed25519 -C "email-associated-with-lthero-big"- Add the public key to GitHub under Settings > SSH and GPG keys. https://github.com/settings/keys
- Update the remote URL to use SSH:
git remote set-url origin git@github.com:lthero-big/HiFi-Mark.git- Ensure the correct SSH key is used by configuring ~/.ssh/config Update the remote URL:
Host github.com-lthero-big
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_lthero_biggit remote set-url origin git@github.com-lthero-big:lthero-big/HiFi-Mark.git最后,输入ssh -T git@github.com 来验证是否是lthero-big
这样操作下来,可以解决账号切换的问题,git credential-osxkeychain erase应该是关键步骤
- 文章作者:
- Lthero博客
- 版权声明:
- 本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议。转载请注明来自 Lthero博客!




