Undo Git mistakes

Fix "refusing to merge unrelated histories"

Happens when you pull a GitHub repo into a folder that already has its own commits, like a new repo created with a README.

Fill these in once
  1. Pull and let the two histories join
    Terminal
    git pull origin main --allow-unrelated-histories

    If Git then reports conflicts, fix them like any merge conflict.

  2. Push the result
    Terminal
    git push -u origin main

Check it worked

  1. See both histories joined
    Terminal
    git log --oneline --graph -10
Undo it
  1. Stop if it goes wrong (before committing)
    Terminal
    git merge --abort
  1. Pull and let the two histories join
    Terminal · Ubuntu / Debian
    git pull origin main --allow-unrelated-histories

    If Git then reports conflicts, fix them like any merge conflict.

  2. Push the result
    Terminal · Ubuntu / Debian
    git push -u origin main

Check it worked

  1. See both histories joined
    Terminal · Ubuntu / Debian
    git log --oneline --graph -10
Undo it
  1. Stop if it goes wrong (before committing)
    Terminal · Ubuntu / Debian
    git merge --abort
  1. Pull and let the two histories join
    PowerShell
    git pull origin main --allow-unrelated-histories

    If Git then reports conflicts, fix them like any merge conflict.

  2. Push the result
    PowerShell
    git push -u origin main

Check it worked

  1. See both histories joined
    PowerShell
    git log --oneline --graph -10
Undo it
  1. Stop if it goes wrong (before committing)
    PowerShell
    git merge --abort