0

I ran into an issue where a change to the case of a file wouldn't push to my remote repo.

I tried using git mv to change the title but it wouldn't work. I changed the name of the file on GitHub itself and committed the change to the repo. Now my local repo won't push changes to remote.

I'm reluctant to pull an older commit into my local repo as I've made a lot of changes that I don't want to lose and have been unable to commit remotely. Is there anyway around this?

cd would-you-rather
git add .
git commit -m '9th commit'
On branch main
Your branch and 'origin/main' have diverged,
and have 3 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
 git push  
To https://github.com/xxxx/xxx.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/xxx.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.
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • You must combine your work (locally) with "their" (your) work over on GitHub. Either that, or you can throw away "their" work (i.e., your work over on GitHub) using `git push --force`. But presumably you'd like to keep your work, as well as your work. Consider using `git fetch` followed by either `git merge` or `git rebase`. – torek Oct 19 '21 at 15:08

1 Answers1

0

I think you changed something in the Github web and you haven't download it yet. I usually see this when I, for example, changed the README file in the Github web UI, saved, and then changed some file locally, and want to push. As the change is done in web to README, and I didn't download it yet, we have a conflict/diverge.

You may want to move your local changes to another branch, like temp, check out to master, pull, and rebase your temp to master, so they got merged. And all is clean. If you want to reset your last commit in master to "release" them to staging area, reset --soft HEAD~1 will do. Then you can see your last commit is in not-commit status now. Then you can checkout -b temp, commit -m your local changes, and check out back to master, pull, and rebase temp onto master.

WesternGun
  • 11,303
  • 6
  • 88
  • 157