GitHub uses the email address in the commit header to link the commit to a GitHub user. If your commits are being linked to another user, or not linked to a user at all, you may need to change your local Git configuration settings, add an email address to your account email settings, or do both.
Push as same username, but to different github accounts After this, if you'll push using git push -u origin-username master , this will prompt you for the password. This is a good trick for multi accounts.
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
NB: GitHub will still identify your commit based on the email only.
I'm using Windows 10 and I faced the same issue today. In my case my credentials for different user were saved by Windows Credential manager. Thus deleting/unsetting git credentials with below command,
git config --global --unset credential.helper
didn't help. I had to manually delete the entry in Windows by following the below way,
Start --> Control Panel ---> User Accounts ---> Manager your credentials ---> Windows Credentials
Then search for an entry like, git:https://github.com and remove it. It works fine after that.
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://[email protected]/USER/REPO.git
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With