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 push them with another username, that's a user from my organisation (my company) with no commit at all and it seems it belongs to no one : (check gallery first pic)
But this doesn't happen when I use Github for mac, in the feed I see the commits pushed by myself.
The problem also affects my personal repositories, my terminal says that I don't have the permission to push commits on those repositories (which is obviously wrong) since it tries to push it with this user : (check gallery second pic)
Guess what ? This doesn't happen with Github for mac too.
I changed my computer to a brand new one few days ago, so I reset'ed all my ssh key of github and left only a new one generated by Github for Mac so I don't think that there's some ghost user/ssh key hidden somewhere, this hdd is brand new : (check gallery third pic)
My .gitconfig file is all clear, there's only my credentials : (check gallery fourth pic)
I really don't get it, help, StackOverflow, you're my only hope.
(My apologies for my poor Gimp skills and the Star Wars reference)
EDIT : ssh-add -l
only shows the good ssh key created by github for mac and I have only one github account
EDIT2 : ssh -T git@github.com
recognize me as the good user.
EDIT3 : After a few tests it looks like my terminal does the commits with my username, but pushes them with the other one, Github for mac commits and pushes with the good username.This situation happen with every repo I have/make (even new ones).
EDIT4 : In a personal repository git log --pretty="%h %an %ae"
shows my good username
EDIT5 : No sign of environment variables that would override my credentials in my env
. Even if I try to set those variables with the good credentials problem persists.
EDIT6 : Things work back normally if I force the user in the path of /.git/config
of a repository but I don't think that's the good option : http://USER@github.com/USER/REPO.git
EDIT7 : We deleted the git user that pushed the commits for me and this brings another error : remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/USER/REPO.git/'
FINAL EDIT : I installed git with homebrew, typed git config --global push.default simple
and now it takes my credentials even without forceing the user. That's strange. Thanks everybody for your help, you're great guys !
I just had this problem at work. The builtin git that ships with mac or comes when you install xcode caches git credentials in keychain. The fix for me was to:
start keychain access (start spotlight via cmd + space, type keychain, press enter)
Under keychains on the upper left, select "login"
Under category on the left, select "passwords"
find the name "github" and delete it.
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
Despite all the great options given by other users, the only way to fix this was to reinstall git completely and type git config --global push.default simple
to rewrite good credentials.
it looks like my terminal does the commits with my username, but pushes them with the other one
Author and committer name and email (which are important for GitHub) are derived from:
git config user.name
git config user.email
However, as mentioned in git config
and git commit-tree
, those values can be overridden by environment variables:
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL
So double-check those variables.
Things work back normally if I force the user in the .git/config
of a repository but I don't think that's the good option.
But it should be a good solution.
When using an https url, I always specify the user in it to make sure the authentication is done with the right user.
http://USER@github.com/USER/REPO.git
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.
A temporary solution is first run killall ssh-agent
then add the ssh keys generated for the account you need to use ssh-add ~/.ssh/id_4shameer
It will help us to work on multiple github account when we will get the error of type ERROR: Permission to user/repo-git.git denied to username.
The solution for me was to add an entry in my ~/.ssh/config file for github. I had to do this because:
- I had multiple github accounts with the same key (don't do this!)
- when you 'git push' using ssh, your computer grabs id_rsa by default and uses that as its ssh identity.
- github can't (unsurprisingly) deconflict which account you mean, since it's basing the account off the key it is presented, which if tied to more than one account, leads to pain like this. The killer is, for a long time, I was getting away with this and things just worked out.
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.
clearing keychain didn't help... I had to ssh-add -D
and re-add the key with ssh-add <keyfile>
I solved this problem removing (or renaming to *.bak) the id_rsa and id_rsa.pub file on MacOS High Sierra. Idea from here.
I have custom host redirects in ~/.ssh/config that should be applied but used wrong user before I renamed the two files...
That's what worked for me:
- Changing the credentials inside .git-credentials
- Changing the global user.name and user.email inside .gitconfig