0

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!

3
  • You don't sign in in the first place, so you can't sign out either. Instead, each time you run git fetch or git push (or a command that runs those), Git calls up some other Git over the Internet-phone, using a URL. The URL can start with https:// (to use HTTPS) or with ssh:// (to use SSH). If using HTTPS, as you are here, Git will use a credential helper to obtain the credentials (user name and password). The credential helper is OS-specific, so mention your OS and Git version. Commented Jun 1, 2022 at 16:04
  • git version 2.34.1 and macOS BigSur 11.5.2 @torek Commented Jun 1, 2022 at 21:17
  • OK, see bk2204's answer and also look into credential-osxkeychain as described on github here. Commented Jun 2, 2022 at 12:40

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.