如何在 Git bash 中更改 git 帐户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41689395/
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 change git account in Git bash?
提问by Ish Thomas
I have weird problem with Git bash. I have to Github accounts, let's say Aand B. I set my name and email, like in account A:
我对 Git bash 有奇怪的问题。我必须在 Github 帐户,假设A和B。我设置了我的姓名和电子邮件,就像在帐户 A 中一样:
git config --global user.name
git config --global user.email
I initialized new repo, did a commit, then push and git bash
asked me about login and password to github. By mistake I put login and password for account B!! I logged in successfully, but there is no repository I just initialized.
我初始化了新的 repo,做了一个提交,然后推送并git bash
询问我关于 github 的登录名和密码。我错误地输入了帐户 B 的登录名和密码!!我登录成功,但没有我刚刚初始化的存储库。
How can I logout and login to different github account? It's not user.name
nor user.email
如何注销并登录到不同的 github 帐户?这不是user.name
也不是user.email
回答by VonC
Much simpler, as I explained in "How to sign out in Git Bash console in Windows?":
简单得多,正如我在“如何在 Windows 中的 Git Bash 控制台中注销?”中所述:
git credential-manager delete <url>
Here
这里
git credential-manager delete https://github.com
No need to remove the credential helper which is practical for caching user's password.
无需删除可用于缓存用户密码的凭据助手。
回答by saTya
To update your Git credentials, go to Control Panel -> Credential Manager -> Generic Credentials. Find the credentials related to your git account and edit them to use the updated password.
要更新您的 Git 凭证,请转至控制面板 -> 凭证管理器 -> 通用凭证。找到与您的 git 帐户相关的凭据并编辑它们以使用更新后的密码。
Ref Link: https://cmatskas.com/how-to-update-your-git-credentials-on-windows/
参考链接:https: //cmatskas.com/how-to-update-your-git-credentials-on-windows/
回答by leolmq
My situation is I had change my gitlab.com's account email, then my local git repository can not push. saTya 's answer worked, but in windows 10 1903, it is Control Panel-> Credential Manager-> Windows Credentials-> Generic Credentials.
我的情况是我更改了 gitlab.com 的帐户电子邮件,然后我的本地 git 存储库无法推送。saTya 的回答有效,但在 Windows 10 1903 中,它是Control Panel-> Credential Manager-> Windows Credentials-> Generic Credentials。
回答by bitfishxyz
One solution: change SSH key.
一种解决方案:更改 SSH 密钥。
At the Begin, I have an account A.
Then, I have a ssh key on ~/.ssh/id_rsa.pub
. I add this key to GitHub ssh key list https://github.com/settings/keys.
一开始,我有一个帐户 A。然后,我有一个 ssh 密钥~/.ssh/id_rsa.pub
。我将此密钥添加到 GitHub ssh 密钥列表https://github.com/settings/keys。
When I try to push commit to GitHub in CLI, the GitHub will know who I am.
当我尝试在 CLI 中向 GitHub 推送提交时,GitHub 会知道我是谁。
Now, I want to switch my git account for GitHub. I just add transfer ~/.ssh/id_rsa.pub
to my account B in GitHub settings.
现在,我想为 GitHub 切换我的 git 帐户。我只是~/.ssh/id_rsa.pub
在 GitHub 设置中将转账添加到我的帐户 B。
After this, when I try to push to GitHub, GitHub will think I am B.
在这之后,当我尝试推送到 GitHub 时,GitHub 会认为我是 B。
回答by Sajib Khan
git credentials will be searched for ~/.git-credentials
or ~/.config/git/credentials
files. You can search these files and if found then modify it.
将搜索 git 凭据~/.git-credentials
或~/.config/git/credentials
文件。您可以搜索这些文件,如果找到则修改它。
$ git config --global --unset credential.helper
# search file
$ sudo find / -type f -name .git-credentials
$ sudo find / -type f -name credentials
For Windows, manager
stores your credentials. It has a Control Panel Interface
where you can edit or delete
your stored credential.
对于Windows,manager
存储您的凭据。它有一个Control Panel Interface
您可以edit or delete
存储凭证的地方。
$ git config --global credential.helper manager