问题
I have weird problem with Git bash. I have two Github accounts, let's say A and B. I set my name and email, like in account 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.
How can I logout and login to different github account? It's not user.name
nor user.email
回答1:
Much simpler, as I explained in "How to sign out in Git Bash console in Windows?":
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.
回答2:
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.
回答3:
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.
Ref Link: https://cmatskas.com/how-to-update-your-git-credentials-on-windows/
回答4:
If you're already connect to any github account after some time you went to pull or push some other repository which belong to some other account.
Example:
I have already connected or my github account username and password is verifed which is "account@gmail.com" it work and find everything is okay, but if I want another directory which is belong to some other account. as I pull it. gitbash generates an error "your required repository is not found". It was actually due to connecting your gitbash to an old account. First of all you have remove all old credentials and add new account than it will work fine
example:
to rmove old credational used this command
git credential-manager delete https://github.com
and add again username user name and email
git config user.name = "new_username"
git config user.email= "newEmail@gmail.com"
after the verification push or pull you repository
git pull -u origin master
that it will work fine and your code will push or pull my remote repository which is belong to other account.
回答5:
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 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.
$ git config --global credential.helper manager
回答6:
One solution: change SSH key.
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.
When I try to push commit to GitHub in CLI, the GitHub will know who I am.
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.
After this, when I try to push to GitHub, GitHub will think I am B.
回答7:
In windows search for Manage window credentials
This window will get opened
in that look into generic credentials for git login, Then remove it by expanding it and pressing remove. After try to push your code via git bash, it will automatically ask you to login.so you can login with your another account. hope its helpful.
回答8:
If you are not able to clone from repo saying git clone getting remote repository not found even if the repo exist in git bash. Here you just need to delete the old credential and then try to access the repo with proper repo account access credentials.
git credential-manager delete https://github.com
( deleteing old credential)
In repo url add <username>@
before github.com
git clone --branch https://<username>@github.com/abhinav/myproj.git
Now you will get a login popup so provide the credentials
Then cloning will be performed successfully.
回答9:
Change username and email global
git config --global user.name "<username>"
git config --global user.email "<email>"
Change username and email for current repo
git config user.name "<username>" --replace-all
git config user.email "<email>" --replace-all
来源:https://stackoverflow.com/questions/41689395/how-to-change-git-account-in-git-bash