Main - diverged (Git)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

The problem

When the root of a repository is the PWD, git commands work! In this case: git status pretty much said the same as the status bar at the top of Sublime Merge

In summer 2023, I somehow screwed up our main (and only) repository. Subsequently, I didn't use the repository at all for some months. Other folks did, and I would like to use it again. When I opened the repository in Sublime Merge, I noticed that the last updates were from months ago - Obviously, my repository hasn't been synced with the rest of the world.

However, when I tried to Pull, Sublime Merge gave an error:

main - diverged
Independent commits have been made to main (14 commits) and origin/main (52 commits). A merge or rebase can be used to combine these changes


  • I think I've edited some scripts in my local repository, but the edits haven't been committed → Judging by the message in the image somewhere here, it's only one file, and that one doesn't need to be preserved.
  • Other folks have edited some scripts - Important that those changes don't get overwritten
  • Preferably, I would sync my repository with what others have done, and have the opportunity to compair the scripts that I have been editing meanwhile.

Sublime Merge suggests three options:

Option: Merge:

Merge main and origin/main
Runs "git merge origin/main"

Option: Rebase:

Rebase main onto origin/main
Runs "git rebase origin/main --autostash"

Option: Hard Reset:

Hard reset main to origin/main
Runs "git reset --hard origin/main"

The one locally changed file, doesn't need to be preserver, so let it be overwritten → git pull: Doesn't work: Error error: Your local changes to the following files would be overwritten by merge: src/ Just deleting the local files, seems a bit rough.


I think I found the answer here:

$ git fetch --all
$ git branch backup-main
$ git reset --hard origin/main

HEAD is now at 0d49bc5 Update