166

I have an issue with git and my terminal. Here's a gallery to show you my issue.

When I push commits from my terminal, git says I push them with another username, that's a user from my organization (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 !

Mehdi Charife
  • 722
  • 1
  • 7
  • 22
Yinfei
  • 1,943
  • 2
  • 12
  • 13
  • 3
    check `~/.gitconfig` and `$project_root/.git/config` files. One of those two is surely misconfigured for user name. – Anshul Goyal Feb 06 '14 at 22:31
  • 1
    Thanks for your answer ansh0l. `~/.gitconfig` is clear and so is `$project_root/.git/config`. In fact I have this issue with every personal project, work projects can be pushed since this other user belongs to my organisation that owns those repositories. – Yinfei Feb 06 '14 at 22:34
  • 1
    Do you have multiple github accounts then? One for company, the other for personal usage? – Anshul Goyal Feb 06 '14 at 22:36
  • Nope, only one for everything. – Yinfei Feb 06 '14 at 22:36
  • 1
    An annoying solution would be to just regenerate another SSH key. If you are using your current SSH key with another service it would be pointless. – Eduardo Bautista Feb 06 '14 at 22:40
  • What is the output if you run `ssh -T git@github.com`? – Anshul Goyal Feb 06 '14 at 22:41
  • Thanks for your answer Eduardo. I only use git with this computer and with my terminal or github for mac, they both acknowledge the same ssh key (which is brand new !)... – Yinfei Feb 06 '14 at 22:41
  • As I edited ansh0l, `ssh -T git@github.com` recognize me as the good user. – Yinfei Feb 06 '14 at 22:43
  • What is the output in case you do `git log --pretty="%h %an %ae"`? Is it corresponding to the correct user? ` – Anshul Goyal Feb 06 '14 at 22:57
  • Yes ansh0l, everything is good. – Yinfei Feb 06 '14 at 23:02
  • I think one way or the other, you have managed to screw up your ssh keeys. Github for mac uses https connection, so that's why it is workng fine (no ssh keys involced). The step `ssh -T git@github.com` suggests that the ssh key is configured fine, though to which account we don't know. So, only one option remains - maybe you are using an incorrect remote url? Check `$project_root/.git/config` file for the value of the remote, I think that has to be set incorrectly. – Anshul Goyal Feb 06 '14 at 23:34
  • Yup, I think my SSH keys were a mess. A simple drop of all of them and pushing a new one would have fixed my issue I guess :) – Yinfei Jul 29 '15 at 10:02
  • [this](https://stackoverflow.com/a/15382950/7926064) worked for me on windows – BNT Jun 28 '17 at 11:46

30 Answers30

197

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.

user542833
  • 11,696
  • 3
  • 16
  • 6
97

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.

Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148
Nithin
  • 5,470
  • 37
  • 44
  • 11
    This is the only answer that explains why it was persistently using the wrong github account despite my `user.email` being set correctly. Wish I could upvote five times. – Chris Nov 28 '17 at 06:29
  • 4
    in my case removing ssh key worked like a charm `ssh-add -D` – rPawel Jan 03 '18 at 16:15
  • 1
    This was the only answer that worked for me. Thanks!! – Edward Hartnett May 23 '18 at 13:54
  • The only option that worked. It doesn't make sense why git would not pick the right key. Since we are mentioning the ssh file it has to use in config. – Revanth Kumar May 24 '18 at 18:51
  • 1
    When I do `ssh-add -l` I get an answer that doesn't help. It types out `4096 SHA256:lotsOfGibberish,about40chars (RSA)` I don't know how to us this information. – MiguelMunoz Nov 17 '18 at 05:42
  • 2
    "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. – Bolun Zhang Mar 22 '19 at 21:31
  • Yes you are right. I wrote that in the context of the question which is `ssh`. But thanks for pointing out the confusion. I will add a note. – Nithin Mar 23 '19 at 08:13
  • You can use multiple identities with GitHub using ssh, but it involves ssh configuration, not GitHub. Here's a decent walkthrough, but in ~/.ssh/config, add IdentitiesOnly yes: https://medium.com/@therajanmaurya/git-push-pull-with-two-different-account-and-two-different-user-on-same-machine-a85f9ee7ec61 For details, see `IdentitiesOnly` in `man ssh_config`. – mellow-yellow Sep 28 '19 at 20:59
40

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.

matt wilkie
  • 17,268
  • 24
  • 80
  • 115
Gowtham
  • 513
  • 7
  • 10
  • You say it "didn't help" but if it gave you the message that it couldn't lock the config file then the problem is simply that you need to run it from an elevated Command Prompt, as was pointed out in a comment above. – Stefan Jul 30 '20 at 20:30
28

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 get the error of type ERROR: Permission to user/repo-git.git denied to username.

mshameer
  • 3,431
  • 2
  • 14
  • 15
  • 2
    I did that after having removed any *Github* entry from *MacOS keychain*, and it worked perfectly. Two points, after the ```killall```, the *ssh-agent* has to be restarted with ```eval "$(ssh-agent -s)"```, and the ```ssh-add```command has to be executed with ```sudo```. – arvymetal Jul 25 '17 at 15:42
  • This was the only solution that worked for me. After doing so, I also had to regenerate a new ssh key and add it to the agent, add it to my github account, and then reauthenticate with github. Then I did `ssh -T git@github.com` to re-authenticate with github, and then everything went back to normal. Thank you! – ttemple Jul 31 '23 at 20:56
25

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your reply VonC ! Unfortunately, my `git config`credentials are right and there's no environnement variables set in my `/username/.bashrc` file... – Yinfei Feb 07 '14 at 09:36
  • @Yinfei84 nonetheless, check your '`env`' output. – VonC Feb 07 '14 at 09:41
  • @Yinfei84 what would happen if (to test it out) you set those variables explicitly, and try a commit and a push. Would that work better then? – VonC Feb 07 '14 at 10:43
  • I just did it and the problem persists. – Yinfei Feb 07 '14 at 10:52
  • @Yinfei84 yet setting the user name and email in the local config seems to work, if I understand your edit 6 correctly. – VonC Feb 07 '14 at 11:39
  • 2
    Excuse me if I wast clear, I meant that it worked if I force the user on the path like : `http://USER@github.com/USER/REPO.git` – Yinfei Feb 07 '14 at 11:41
  • @Yinfei84 interesting, so it has less to do with the commit, and more with the URL. Note that I always set the user when using an http url, in order to help git to select the right user when pushing. – VonC Feb 07 '14 at 11:43
  • I neved had to do this before and since I joined my company's organization on github it happens. The main problem is that my terminal pushes with this user that seems to be registered nowhere in my computer unless I force the user. That's really weird. Is there any way to set this option to force ther user with every repository ? – Yinfei Feb 07 '14 at 12:33
  • @Yinfei84 it defaults to the user who executes the `git push`. I always set it explicitly as I have many different accounts for different remotes. – VonC Feb 07 '14 at 12:40
  • I'm okay with that except that this other user that pushes my commit is nowhere to be found in my computer :( – Yinfei Feb 07 '14 at 12:55
  • 1
    `http://USER@github.com/USER/REPO.git` is actually the ONLY workable option. In other cases Git will send password of random user to remote servers, usually not owned by the user. – wvxvw Feb 25 '18 at 11:37
21

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.

Yinfei
  • 1,943
  • 2
  • 12
  • 13
  • @VonC, despite your answer was great, it didn't work at all. This is the only solution that worked for me. I wonder if it's git issue or OSX... – Seb Wilgosz Mar 25 '16 at 07:05
  • 52
    `git config --system --unset credential.helper` worked for me, I'm now asked for my GitHub credentials on push again and can supply the correct user ID and password. – CodeManX Sep 02 '16 at 12:44
  • 2
    @CoDEmanX your's was the only answer which worked for me. For anyone else who comes across this, it was because we use 2FA at work with github and I needed to generate a token from the github gui first and use that as my password from the command line after I had reset my local credentials ! check out [https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/) for details – vancouverwill May 09 '18 at 09:14
  • Its just the .gitconfig file . Either remove that or reset it... I faced this problem when I submitted a trial project for an interview. Damn it hurts though. Its with the config file – Girish Jul 22 '18 at 18:23
  • `git config --system --unset credential.helper` does not work on Windows 10 git bash: `error: could not lock config file C:/Program Files/Git/mingw64/etc/gitconfig: Permission denied` – alex Sep 30 '19 at 16:17
  • I have a problem with 1 repo only. Doing this `--global` thing, I'm not sure how that will affect all the dozens of other repos I have. – Thomas Weller Jan 12 '20 at 10:58
  • @alex you need to run from an elevated (Administrator) command prompt – matt wilkie Apr 16 '20 at 21:46
  • I had to run this with `sudo` otherwise I got `error: could not lock config file /etc/gitconfig: Permission denied`. (mac user) – Marlo Apr 11 '21 at 03:25
17

What a pain in the butt!

problem:

  1. create a repo on git hub
  2. clone to local machine
  3. can not push 403.

turns for unknow reason git push was using the wrong user. I have a couple of different git hub user ids. I work for 2 different companies and also have a student id

I am working on a mac. here is what I finally did

1) remove the credential.helper

  • some how the credential helper got set to osxkeychain
  • when I started keychain, click on login, passwords and searched for github I found 3 entries. I have no idea how keychain could possible know which one to use

a. you need to figure out where the credential.helper is configured

git config --local credential.helper
git config --global credential.helper
git config --system credential.helper

b. once find the correct fig file remove it as follows

git config --global --unset credential.helper

Now in my local repo I hacked the .git/config file

I changed

    url = https://github.com/aedavids/lab3RotationProject.git

to

    url = https://myGitHubUserId@github.com/aedavids/lab3RotationProject.git
AEDWIP
  • 888
  • 2
  • 9
  • 22
  • For me it was good enough to just do step 2 (editing the local `.git/config`) -- no need to clear the cache. – Jasha May 19 '21 at 04:41
  • Ditto - simply editing the config file to provide the correct user name for github fixed the problem for me. Thanks a lot! – Nik Bhatt Apr 06 '22 at 21:53
12

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.

Chitrapal Singh
  • 149
  • 1
  • 2
4

The solution for me was to add an entry in my ~/.ssh/config file for github. I had to do this because:

  1. I had multiple github accounts with the same key (don't do this!)
  2. when you 'git push' using ssh, your computer grabs id_rsa by default and uses that as its ssh identity.
  3. 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.

4

This is how you debug and fix it for ssh url

First, check which user is via ssh:

ssh -T git@github.com

Hi <your_current_github_username>! You've successfully authenticated, but GitHub does not provide shell access.

Login GitHub with the above your_current_github_username Check all configured ssh keys: https://github.com/settings/keys

Method 1:

Remove the ssh key from your_current_github_username

Method 2:

  • determine which key was associated with your_current_github_username

    cat ~/.ssh/id_*.pub
    
  • Assumming id_rsa is the SSH key of your target github username, in your case it's might be a different file name.

    eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa
    

Method 3:

If no public key was found on your machine (or you've lost it) Then create a new ssh key by ssh-keygen and place it here: ~/.ssh/id_new_keyyyy

eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_new_keyyyy
Neo.Mxn0
  • 953
  • 2
  • 8
  • 25
  • Thanks, an important thing this solution brings up (particularly if using github) is making sure you actually have ssh keys configured in https://github.com/settings/keys . May apply for other remotes that require an ssh key vs. say https style username/password login. – Vivek Gani Jul 11 '23 at 02:40
3

I had a similar issue and it turned out that the problem was the fact that the public key file contained my email address on the last line. That seemed to override the User setting in my config. As soon as I removed my email from the .pub file (and re-uploaded to my repo) Git connected using the correct user.

Mike
  • 628
  • 10
  • 22
  • This worked for me. Not sure why the identifier on the public key file was originally in the format 'name@domain' but it was. – Brian Wagner May 19 '20 at 15:56
3

This has been irking me for around 2 years and I finally took the time today to figure it out. Anything I force-pushed would show up as pushed by a different user on GitHub web or as triggered by a different user on CircleCI web. The culprit seemed to be that my local repos, lazily created via Code > Open with GitHub Desktop from my fork on GH web, were all using HTTPS.

If you're like me, your remote should look like this:

> git remote -v
origin  https://github.com/USERNAME/REPO.git (fetch)
origin  https://github.com/USERNAME/REPO.git (push)
upstream    https://github.com/ORG/REPO.git (fetch)
upstream    https://github.com/ORG/REPO.git (push)

Then I:

  • Ran git config --system --unset credential.helper to clear out my HTTPS credentials; this may not have been necessary so you can try skipping it unless you're in a scenario where you have some bad/invalidated stored credentials.
    • If you're on Mac OS you can also open the Keychain utility application and view/modify/delete individual GitHub.com Internet Password credentials stored in your login keychain. The Access Control tab for these credentials will show a little terminal icon with the name git-credential-osxkeychain under 'Always allow access...'
    • Alternatively, you can play with them in the terminal via git credential-osxkeychain
  • Ensured I had SSH set up by running ssh -T git@github.com, which printed a response confirming I was authenticated.
  • Reconfigured my remotes to use the SSH urls from my fork:
> git remote remove origin
> git remote add origin git@github.com:USERNAME/REPO.git
> git remote remove upstream
> git remote add upstream git@github.com:ORG/REPO.git

# Shorter alternative:
> git remote set-url origin git@github.com:USERNAME/REPO.git
> git remote set-url upstream git@github.com:ORG/REPO.git

Your next pull may tell you to re-set up your upstream tracking branch (the error message prints the syntax for this if you aren't familiar with it).

I suspect that force push events are attributed to a user via credential, and that there is some issue with identifying the user when pushing from an HTTPS clone; to prevent a totally broken experience when a push can't be attributed to a user, there is probably some logic on GH's side that arbitrarily chooses an org user to attribute the event to. Things like ensuring an author was set (even though my user info was displaying as author perfectly fine in the commit log) did not work for me; it makes sense that they wouldn't resolve this issue, because a push may contain many new commits from a variety of different authors. The moral of this story is always use SSH.


Side note: Be wary of any solutions that tell you to update your git config to automatically replace the HTTPS repository URL with an SSH repository URL. There are certain things that approach will very confusingly break, like homebrew taps in private repos (which as of 2021 still only supports HTTPS).

Allison
  • 1,925
  • 1
  • 18
  • 25
  • 1
    `git config --system --unset credential.helper` this is the magic command that resolved my issue, thanks. It cleared the stored credentials and I was able to log in as a different user. – Papooch Jun 24 '21 at 07:26
2

First Go to this path in Windows
Start --> Control Panel --> User Accounts --> Manager your credentials --> Windows Credentials

And Remove the credential from git:https://github.com

Then add your GitHub account username and password from which you want to push the code at the same place.

To check whether git will push from the username that you added now enter the following command in git bash.

git config user.name

This will show you the username from which the git will push. If the username is correct then your problem is solved.

For me this didn't solve the problem it was still showing my previous account username that I removed.

Now enter the username and email Id of the account from which you want to push in the following command in git bash.

git config --global user.name your_username
git config --global user.email your_emaiid

This will now change the user.
Before pushing any code you can verify whether the user is changed or not by again using the following command.

git config user.name
2

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
erwin
  • 442
  • 6
  • 13
2

Steps to add new ssh key to a new git repo on win10:

  1. Generate and save ssh key pair in your .ssh directory. I assume you made them in correct form, because putty gen can generate funny key types by default.
  2. You should have config file in ssh directory (add it as .ssh/config if it doesn't exist yet):

Host github.com // this is for your main default key; remove comments
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa // your current main key; remove comments

Host whatever-host-nickname-you-want
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_second-key // path to new key; remove comments

  1. In your repository where you need a second key do

git config user.name username-from-second-account
git config user.email email-from-second-account

  1. Now change origin in your reposiory usingp reviously set host nickname and username & repo name from new account:

git remote remove origin
git remote add origin git@whatever-host-nickname-you-want:username-from-second-account/repository-name.git

You should be good to go.

Patryk Wlaź
  • 493
  • 5
  • 11
1

What worked for me was to use the Github repo's https URL instead of the ssh URL. I went to the Github project page and copied the https URL into my clipboard, and then pasted it into the second command below:

git remote rm origin
git remote add origin https://[...]
Keith Bennett
  • 4,722
  • 1
  • 25
  • 35
1

In my particular case, the issue was that I was using a .netrc to access github.com and it was configured with a token from a different user:

machine github.com login <another-user-token>
Travis Clarke
  • 5,951
  • 6
  • 29
  • 36
1

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.

jmoz
  • 7,846
  • 5
  • 31
  • 33
1

I had a similar issue while running git via Remote SSH inside of Visual Studio Code. Turns out that VSCode by default sets itself up as authentication handler and sets $GIT_ASKPASS to a script ($HOME/.vscode-server/bin/*/extensions/git/dist/askpass.sh), which it uses to set/override git credentials.

This can be overridden by setting git.terminalAuthentication to false (aka. Git: Terminal Authentication) and effectively removes the $GIT_ASKPASS environment variable from the terminal.

M Jensen
  • 546
  • 3
  • 8
1

It might be because of bad remote URL. You can check it with: git remote -v.

  • BAD: git@github.com:<user>/<repo>.git
  • CORRECT: git@<user>:<user>/<repo>.git

To replace it:

git remote remove origin
git remote add origin git@<user>:<user>/<repo>.git
manuel
  • 11
  • 2
1

I faced the same issue while using several github accounts and despite that push requests were going through the correct username, on github user were set the main account used in --global configuration.

So, the simple fix is just to use local configuration: git config --local user.email second_account_account

That solved the problem for me.

GRigol
  • 393
  • 4
  • 7
0

clearing keychain didn't help... I had to ssh-add -D and re-add the key with ssh-add <keyfile>

Victor Pudeyev
  • 4,296
  • 6
  • 41
  • 67
0

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...

CodingYourLife
  • 7,172
  • 5
  • 55
  • 69
0

That's what worked for me:

  1. Changing the credentials inside .git-credentials
  2. Changing the global user.name and user.email inside .gitconfig
reshetech
  • 853
  • 7
  • 10
0

What worked for me removing the repo and adding it again:

git remote rm origin
git remote add origin git@github.com:fguillen/MyApp.git
fguillen
  • 36,125
  • 23
  • 149
  • 210
0

I have the same problem in windows10 even after uninstall my git, as @user542833 says it is because windows cache and you should remove Github credentials in your windows Credential Manager and when you again attempting to push, windows ask your credential and set it again

Ghazaleh Javaheri
  • 1,829
  • 19
  • 25
0

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.

slim
  • 2,545
  • 1
  • 24
  • 38
0

Had exactly the same issue on my side.

The solution was simple:

Open the local or global git config file, and provide the [author] email explicitly.

enter image description here

Just Shadow
  • 10,860
  • 6
  • 57
  • 75
0

Using this command you can easily pushed to git under a different user name.

git add .
git commit -m "initial commit"
git config --local credential.helper ""
git push https://github.com/youraccount/repo.git --all
0

In my case github CLI was the fix:

gh auth login

Then:

  1. GitHub.com
  2. Yes
  3. HTTPS
  4. Yes
  5. Login with a web browser
ChromeKK
  • 150
  • 3
  • 11