Search code examples
gitgithubcredentials

Reset git credentials (Github)


I have two Github accounts: private and for work. Each associated with different credentials. Let's name these credentials PRIVATE and WORK.

Currently, my system seems to be using the work-related credentials WORK. When I tried to delete/change these credentials and push to my private repo, I still get:

git push --set-upstream origin main
ERROR: Permission to my_private_repo denied to WORK.
fatal: Could not read from remote repository.

I'm using Mac, deleted all git-related items from Keychain. When I do

git credential-osxkeychain erase
host=github.com 
protocol=https

the terminal hangs.

Can you please tell me how to completely remove the WORK credentials from the computer?


Solution

  • First, do check your remote URL is indeed an HTTPS one (if it is SSH, no amount of keychain fiddling would matter, since the ketchain is used to cached HTTPS credentials).

    cd /path/to/repository
    git remote -v
    

    Second, for an HTTPS URL, deleting the credentials would be:

    printf "host=github.com\nprotocol=https\nusername=YourWorkLogin" | git credential-osxkeychain erase