Ish Thomas
Ish Thomas

Reputation: 2460

How to change git account in Git bash?

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

Upvotes: 42

Views: 280743

Answers (11)

testtest
testtest

Reputation: 1

Just use those can change account

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

Upvotes: 0

Дима ООООО
Дима ООООО

Reputation: 11

i had similar problem at "intellegy IDEA", in it's terminal , spent 2 hours, but only need to do: intelliIDEA->references (for Mac IDEA) or file->settings (for windows) to choose gitHub delete account, add new (it can have problems too, in browser need to came in decired account) press apply

Upvotes: 1

shrekuu
shrekuu

Reputation: 2282

I have two github accounts. One for hobby one for work.

I generated another ssh key for work: ~/.ssh/.id_rsa_work.pub
then add it to my work account: https://github.com/jack.

In my ~/.ssh/config, now I added this for work account:

Host github-work
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_work

Then when I want to clone from company repo [email protected]:company_org_name/company_repo_name.git,
I run(note the github-work part):

$ git clone git@github-work:company_org_name/company_repo_name.git

That's it.

Don't forget to set local name and email for company repo right after you run git clone.

git config user.name "my name at company"
git config user.email "my email at company"

Now you have multiple accounts on your device. You won't feel any difference from now on.

Upvotes: 3

VonC
VonC

Reputation: 1330102

Much simpler, as I explained in "How to sign out in Git Bash console in Windows?":

git credential-manager erase <url>

Here

git credential-manager erase https://github.com

No need to remove the credential helper which is practical for caching user's password.

Or (replace xxx wit the output of git config --global credential.helper):

printf "protocol=https\nhost=github.com" | git-credential-xxx erase

# Windows (2020-2021)
printf "protocol=https\nhost=github.com" | git-credential-manager-core erase

# Linux
printf "protocol=https\nhost=github.com" | git-credential-libsecret erase

# MacOs
printf "protocol=https\nhost=github.com" | git-credential-osxkeychain erase

Upvotes: 29

Mubashar Hussain
Mubashar Hussain

Reputation: 307

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 "[email protected]" 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 to remove all old credentials and add a new account. Then it will work fine.

Example:
to remove old credentials, use 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= "[email protected]"

after the verification push or pull you repository

git pull -u origin master

Then it will work fine and your code will push or pull from a remote repository which belongs to other account.

Upvotes: 8

Aravinth
Aravinth

Reputation: 113

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.

Upvotes: 10

abhinav kumar
abhinav kumar

Reputation: 1803

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.

Upvotes: 2

leolmq
leolmq

Reputation: 261

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.

Upvotes: 21

Shuai Li
Shuai Li

Reputation: 2776

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.

Upvotes: 2

saTya
saTya

Reputation: 325

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/

Upvotes: 7

Sajib Khan
Sajib Khan

Reputation: 24204

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

Upvotes: 1

Related Questions