how to log out of one Github account and use another account?
Asked Answered
O

2

18

I was using another github account to practice, and now I set up my own github account. I will be primarily using my own account from now on. My problem is that my computer still is logged in as another github account name (even though I am logged into my own Github account online).

I cannot push anything to my own github repos, because the other account does not have permission to do that, obviously. How do I tell my computer to switch over to my own account so that I can push to my repos in Github online?

Ornamented answered 10/7, 2015 at 22:36 Comment(0)
F
29

If your using OSX, open terminal and run this:

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

to erase the keychain entry. So next time it will prompt you to login.

To view the current credentials cached use the command git credential-osxkeychain get followed by pressing enter twice.

if you press enter only once you will invoke the command but it will apear to hang, if you press enter a second time you will be prompted by a dialog box to confirm access to your keychain and then the information will be returned in terminal


If you would like to prevent this issue in the future you can configure the git helper tool for osx-keychain to store your login credentials associated with the entire path of the repository rather than just the domain which is the default.

In terminal enter the command

git config --global --edit

This will open a configuration file. If you haven't already, you may want to set your default editor so the file opens in your preferred application.. For example, to set Sublime Text as your default editor: git config --global core.editor "subl -n -w"

With the config file opened, search for useHttpPath (or define it if it doesn't exist). And set it's value to true. It should look like this:

[credential]
  helper = osxkeychain
  useHttpPath = true

This will instruct git (as well as github) that any credentials used to login should only be associated with the full repository path that was queried, not for the entire domain (in the case of github) all repositories on Github.com.. So now you can be logged into your repository, and your boyfriend can be logged into his repository and there will be no conflicts between your logins.

Frasch answered 10/7, 2015 at 22:39 Comment(7)
thanks! is there a way to check in the terminal which user is actually logged in currently?Ornamented
maybe git config --listFrasch
@Rory_Perro did my last comment work for what you wanted? I'm curious myself as was not sure.Frasch
I updated my answer with more accurate info as to how to check which user is currently logged in after reading more into credential-osxkeychain.Frasch
thanks @davidcondrey! I needed to have git credentials for both work and personal projects on my mac and your answer provided the solution.Rambow
Thank you @Frasch this was incredibly helpful. I found out that if your config file has both accounts defined, the first step, erasing the keychain entry is not necessary.Ashti
"If you press enter only once..." was the issue I was running into. Thanks for being explicit in your instructions.Ice
T
7

Thanks for your answer, David Condrey.

For anyone having the same issue on Windows 10, the following worked for me. It's only slightly different to the Apple Mac answer.

  1. Using the Git Bash shell / command line, start an editor:

    git config --global --edit
    

    I had only a [user] section in this file. Yours may be different.

  2. Add the following credential section and single line entry to the end of the file:

    [credential]
        useHttpPath = true
    

    Note it's credential, not credentials. You don't need the helper = osxkeychain line, which is for Apple Macs.

  3. Save and Exit the editor.

Now when you git push, a login dialogue window appears (but may be in the background). The Octocat icon appears in the taskbar.


PS: Later, I found this had added a line to the global config and that the following command can be used instead:

git config --global credential.useHttpPath true
Townscape answered 4/2, 2018 at 2:14 Comment(1)
In cmd line works if setting useHttpPath = true, but I use EGit in Eclipse and it is still not working.Oxycephaly

© 2022 - 2024 — McMap. All rights reserved.