Home > Mobile >  Unable to git push, fatal: authentication failed, after username change
Unable to git push, fatal: authentication failed, after username change

Time:12-20

The way I publish my GitHub code updates is by working in a separate folder, then copy-pasting the folder in the GitHub folder that I can commit and push. I am working in git CL (GitHub Desktop's lost me some work somehow so I uninstalled it). The issue is I changed my username recently. Now when I try to push it fails. It has trouble with untracked changes too but I think I fixed that. It keeps showing me the old username in error messages, and hints that I don't get/think are relevant:

 ! [rejected]        gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/old_username/old_username.github.io.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried git config --global user.name new_username

I changed git remote to the one with last week when I had the same issues. That time I ended up pushing just fine.

When I try to /git-credential-manager-core.exe unconfigure to undo past authentication, and try again, the git push fails even after trying to authenticate with my new PAT and username.

CodePudding user response:

You need to change the remote with the new URL of the remote repository after the username change.

git remote set-url origin https://github.com/new_username/repo_name.git

Edit:
However, as the error suggests, the problem is not with the username change. It says all clearly:

the tip of your current branch is behind its remote counterpart

If you need to get the remote change you may pull it with;

git pull <remote-name> <branch-name>

Also you may ignore the remote change and force push you local changes with -f option;

git pull -f <remote-name> <branch-name>

CodePudding user response:

Reinstalling GitHub Desktop (after cleaning up all remnant files) solved this. I then cloned repo again, pasted the changes again, used the same credentials as before (same PAT).

Might've been a GitHub bug.

  • Related