git 如何注销一个 Github 帐户并使用另一个帐户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31351359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to log out of one Github account and use another account?
提问by Rory Perro
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).
之前用另外一个github账号练习,现在建立了自己的github账号。从现在开始,我将主要使用我自己的帐户。我的问题是我的计算机仍然以另一个 github 帐户名登录(即使我在线登录到自己的 Github 帐户)。
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?
我无法将任何内容推送到我自己的 github 存储库,因为显然另一个帐户无权这样做。我如何告诉我的计算机切换到我自己的帐户,以便我可以在线推送到我在 Github 中的存储库?
回答by davidcondrey
If your using OSX, open terminal and run this:
如果您使用的是 OSX,请打开终端并运行:
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.
要查看缓存的当前凭据,请使用该命令,git credential-osxkeychain get
然后按两次 Enter。
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.
如果您想防止将来出现此问题,您可以为 osx-keychain 配置 git helper 工具来存储与存储库的整个路径相关联的登录凭据,而不仅仅是默认域。
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"
这将打开一个配置文件。如果您还没有,您可能需要设置默认编辑器,以便文件在您首选的应用程序中打开。例如,将 Sublime Text 设置为您的默认编辑器: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:
打开配置文件后,搜索useHttpPath
(或定义它,如果它不存在)。并将其值设置为true
. 它应该是这样的:
[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.
这将指示 git(以及 github)用于登录的任何凭据只应与查询的完整存储库路径相关联,而不是与整个域(在 github 的情况下)Github.com 上的所有存储库相关联。 所以现在您可以登录您的存储库,您的男朋友也可以登录他的存储库,并且您的登录之间不会有冲突。
回答by tebb
Thanks David Condrey.
谢谢大卫康德雷。
For anyone having the same issue on Windows 10, the following worked for me. Only slightly different to the Apple Mac answer.
对于在 Windows 10 上遇到相同问题的任何人,以下内容对我有用。与 Apple Mac 的答案仅略有不同。
Using the git bash shell / command line, start an editor:
使用 git bash shell / 命令行,启动编辑器:
git config --global --edit
I had only a [user] section in this file. Your's may be different.
我在这个文件中只有一个 [user] 部分。你的可能不一样。
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.
您不需要 helper = osxkeychain 行,这是用于 Apple Mac 的。
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.
现在,当您 'git push' 时,会出现一个登录对话窗口(但可能在后台)。Octocat 图标出现在任务栏中。
.
.
PS: Later, I found this had added a line to the global config and that the following command can be used instead:
PS:后来我发现这在全局配置中添加了一行,可以使用以下命令代替:
git config --global credential.usehttppath true