起因是本地git存在多个账号,提交时显示登录的是lthero-g,我需要切换回lthero-big

1
2
3
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:

1
2
3
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:

1
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

    1
    git credential-osxkeychain erase

    Then enter:

    1
    2
    host=github.com
    protocol=https

    Press Enter twice to clear the cached credentials.

  • 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:

    1
    ssh-keygen -t ed25519 -C "email-associated-with-lthero-big"

    Save it (e.g., ~/.ssh/id_ed25519_lthero_big).

  • Add the public key to GitHub under Settings > SSH and GPG keys.

  • Update the remote URL to use SSH:

    1
    git remote set-url origin git@github.com:lthero-big/HiFi-Mark.git
  • Ensure the correct SSH key is used by configuring

    ~/.ssh/config

    1
    2
    3
    4
    Host github.com-lthero-big
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_lthero_big

    Update the remote URL:

    1
    git remote set-url origin git@github.com-lthero-big:lthero-big/HiFi-Mark.git

这样操作下来,可以解决账号切换的问题,git credential-osxkeychain erase应该是关键步骤