The repository was created with its own first commit
CommonYou started the project locally, then created the repository on GitHub, GitLab or Bitbucket with a README, licence or .gitignore. The host made a first commit, your machine made another, and neither history contains the other. This is the usual way to meet the error, on the first pull after adding the remote.
Confirm
git fetch origin && git rev-list --max-parents=0 HEAD origin/<branch>
Two different commit hashes, one being the host's initial commit (often titled Initial commit) and the other your first local commit
Fix
- Rebase your commits onto the remote's. Your work ends up after the host's first commit in one straight history, with no merge commit and nothing to force.
- If both sides added the same file, usually README.md, the rebase stops on that file. Keep the content you want,
git addit andgit rebase --continue. - Push normally afterwards. The remote's commit is now an ancestor of yours, so it is a fast-forward.
git fetch origin git log --oneline origin/<branch> git rebase origin/<branch> git push -u origin <branch>
Check the log first: it should show only what the host created. git pull --rebase origin <branch> does the fetch and rebase in one step. Reproduced on Git 2.50: the rebase succeeded and left a single root commit.