All fixes

Help, I get “refusing to merge unrelated histories”

Your local repository and the remote started separately, typically with a README created on GitHub. Join them once.

What Git says~/my-app
git pull --no-rebase origin main
fatal: refusing to merge unrelated histories

The fix

  1. git pull --no-rebase origin main --allow-unrelated-histories

    Merges the remote history, often just a README, into yours. --no-rebase makes it a merge no matter how pull is configured.

  2. git push -u origin main

    Pushes the combined history and links main to origin/main.

What happens to your history
BeforeABRHEADmainorigin/main
AfterABRMHEADmainorigin/main

Why this works

The two histories share no common commit, so Git refuses to merge them by default to protect you from combining two unrelated projects by mistake. When they really are the same project, the flag allows the merge once. If both sides have a file with the same name, such as README.md, resolve that conflict like any other.