简体   繁体   中英

Force git to push as locally configured user

I have two GitHub accounts that I am managing, let's say accountX and accountY In the beginning, I was using only one, so I had a global config with its username and email (accountX). Now I want to use the second one. I created a repo, I used git config to configure the username and email locally for this repo.

I made a commit, and git log shows a proper username and email (the ones configured locally, so the second account) under the commit. Then I've added a repo address (created on this second account) and I wanted to git push . Unfortunately, I get the message, that accountX doesn't have the permissions to this repo (and it shouldn't), but why isn't it using the one I configured locally? Is it because of my SSH key stored for the accountX ? So I want to push via ssh and it uses a key generated way back in history for accountX ?

Do you guys see my mistake here?

Using git config user.xxx commands is only for setting author and committer names, not for authentication.

For using the right account, you need to record a second SSH URL, using your second private key.

This is done through a ~/.ssh/config file.

git remote add origin2 second
git push second master

With " second " being defined in the aforementioned ~/.ssh/config file.

Host second
   Hostname yourGitServer.com
   User git
   IdentityFile c:/path/to/your/second/private/key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM