Home > Blockchain >  Logging out from git cli
Logging out from git cli

Time:06-02

How do I sign out from a certain account on git through the command line?

I have two accounts and I don't know how I ended up with the wrong one. And after trying different approaches, I can't seem to find a way to sign out from there.

When I push, I get:

remote: Permission to yyyyyyyy/xxxxxx.git denied to ZZZZ. //<---- wrong acc
fatal: unable to access 'https://github.com/yyyyyyyy/xxxxxx.git/': The requested URL returned error: 403

I've tried:

git config --global --unset-all
git config --global --unset user.name
git config --global --unset user.email
git config --global --unset credential.helper
git remote rm origin
git remote add origin [email protected]:<username>/<repo>.git
git push --set-upstream origin <my-branch>
rm ~/.gitconfig

But I always get the same error.

Thanks!

CodePudding user response:

Git doesn't have the concept of a login. What it does have is a credential helper that stores credentials, which on macOS is set to the default value of osxkeychain in the system config.

The Git FAQ explains how to clear the credential helper:

echo url=https://github.com | git credential reject

Note that if you have two accounts, the best way to handle this for HTTPS is to always place the account in the URL when setting up a remote. That is, your URL should look like https://[email protected]/git/git.git or https://[email protected]/git/git.git. Then, because you have different usernames, the credential helper will store the credentials separately for each user and automatically use the right ones. This approach is also outlined in the Git FAQ.

Note that if you need to change the URL for an existing remote, you can do so like so: git remote set-url origin https://[email protected]/git/git.git.

  • Related