-1

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.

Daniel
  • 99
  • 1
  • 5
  • https://stackoverflow.com/questions/22844806/how-to-change-my-git-username-in-terminal you can solve your problem from this link – AliRhz Dec 19 '21 at 16:09
  • Thank you, but I solved it by reinstalling GitHub Desktop and git and repeated the steps. Maybe there was a GitHub bug or maybe some cache needed clearing... – Daniel Dec 19 '21 at 16:14
  • "Reinstalling GitHub Desktop fixed it" would imply that this a GitHub Desktop problem, not a Git problem, nor a GitHub problem. It's odd that you'd see it from the command line then, though. "Reinstalling Git fixed it" would imply a cached entry somewhere and would make sense for seeing it from the command line. For anyone in the future who comes across this, if you can pin down which one was the case, that would help them. – torek Dec 20 '21 at 02:25
  • GH Desktop and git both deal with the same workflow, and I had an auth issue with both. The cached entry would be my git credentials in credential manager, which I don't know where to find or even if I can show it. Doesn't matter they're gone now. I’ve asked my question best I could, as I’m also working w incomplete info. I am no expert, so I can’t pin down what the issue was exactly. All I can say is the trusty “off and back on again” worked. – Daniel Dec 20 '21 at 04:14

1 Answers1

1

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>
# resolve any conflicts and then push
git push <remote-name> <branch-name>

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

git push -f <remote-name> <branch-name>
Tharindu Sathischandra
  • 1,654
  • 1
  • 15
  • 37
  • Thank you - I did that, authentication still fails - with and without PAT. With and without credential manager. Investigating... – Daniel Dec 19 '21 at 15:27