0

I have a local and remote repository of a single line file. On my local folder, I made a few changes and am trying to push them to github.

I have made no changes to the remote repo, but somehow when I try to push from the command line it says I'm behind the remote counterpart, and tells me to try a pull. But that also fails due to "unrelated histories".

andy@andy-VirtualBox:~/Code/EditMe$ git push origin main
To https://github.com/MorningPants/EditMe
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/MorningPants/EditMe'
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.
andy@andy-VirtualBox:~/Code/EditMe$ git pull origin main
From https://github.com/MorningPants/EditMe
 * branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

after browsing similar questions, this info also seemed pertinent:

andy@andy-VirtualBox:~/Code/EditMe$ git remote -v
EditMe  www.github.com/MorningPants/EditMe (fetch)
EditMe  www.github.com/MorningPants/EditMe (push)
origin  https://github.com/MorningPants/EditMe (fetch)
origin  https://github.com/MorningPants/EditMe (push)
Andy
  • 3
  • 2
  • 1
    If someone had rebased and pushed to the remote, then there will be mismatch in the timeline by the time you push it... try looking for local and remote SHA's mismatch or try a git pull / rebase.... – Neyo Jun 19 '21 at 04:44
  • Maybe this will help. https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase. Most answers suggest you to perform `git pull origin branchname --allow-unrelated-histories`, fix merge conflict and push. – Sagar Adhikari Jun 19 '21 at 04:46

1 Answers1

1

Try again in a new folder.

git clone https://github.com/MorningPants/EditMe.git

And edit or copy the edited file into the new folder.

git add .

git commit -m "edited"

git push origin main
pullidea-dev
  • 1,768
  • 1
  • 7
  • 23