起因是本地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: 403

These 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.git

This 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 erase
host=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"
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_big
git 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应该是关键步骤