I have an issue with git and my terminal.
Here\'s a gallery to show you my issue : http://imgur.com/a/6RrEY
When I push commits from my terminal, git says I
Just spent 6 hours figuring this out when trying to push to a new GitHub pages repo on a new account.
Even after setting the config user.name and user.email it would default to my main account.
This is because the ssh key will default to id_rsa (my main account).
To use the new account I had to run:
ssh-add ~/.ssh/my_new_key
which will then make git use the new key when pushing.
If you are using MAC, then go to Keychain Access and remove the entry of the user for which you don't want git access.
The comment from @bolun-zhang helped me finally solve this:
"github identifies you by the ssh key it sees, not by any setting from git"
IMHO, this is inaccurate and very misleading/wrong. When you are using SSH to interact with github, the permissions are checked by the SSH. However, github determines the authorship of commits based on the email gitconfig regardless of the SSH key.
For me, this turned out to be completely accurate. Reguardless of what I set in ~/.ssh/config
even using: export GIT_SSH_COMMAND="ssh -i ~/.ssh/some-key"
, an alternate username was still being selected.
The problem and solution was that git config user.email
was matched to the alternate email of another github user.
After removing that email from the other github user, the commit worked fine.
Ultimately, as @venkatesh-murugesh pointed out, you need to set:
git config user.email
To match the email address of the github user account that should own the commit.
Of course, you'll want to use ~/.ssh/config
or GIT_SSH_COMMAND
to make sure that SSH is using the correct key. Test it with:
ssh -T git@github.com
No matter what I tried I couldn't get the name to change on github because the commit itself needed a different author:
git commit --amend --author="Author Name email@address.com"
Now the commit shows the correct account.
The solution for me was to add an entry in my ~/.ssh/config file for github. I had to do this because:
The entry I added is:
Host github.com
Hostname github.com
Port 22
User waterproofpatch
IdentityFile ~/.ssh/id_rsa_waterproofpatch
I had created a new key, unique to my account, as id_rsa_waterproofpatch. This entry in my ssh config specifies that for connections to github.com, I wish to present this key.
Another solution would probably have been for me to log into the other account, delete the duplicate ssh key.
github identifies you by the ssh key it sees, not by any setting from git.
Therefore, you need to ensure that your work account's ssh key is not in your keyring when you try to push from your personal account and vice versa.
Use ssh-add -l
to determine which keys are in your keyring, and ssh-add -d <keyfile>
to remove a key from your keyring, if it dosent work remove the 'unwanted' ssh key from ~/.ssh/config
.
source
NB: Github will still identify your commit based on the email only.