Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
866 views
in Technique[技术] by (71.8m points)

git - how to log out of one Github account and use another account?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...