Skip to content

git pull silently created merge commit

Quick summary

You ran git pull and got a merge commit you did not expect — the default pull strategy merged instead of fast-forwarding or rebasing.

Why this happens

  • Your local branch had commits that the remote did not, so git pull --merge created a merge commit instead of fast-forwarding

  • You did not configure pull.rebase true, so git defaults to merge which creates merge commits for divergent histories

  • A teammate pushed commits that diverged from your local history, making a fast-forward impossible and triggering a merge

Minimal example

✗ Broken code
git pull  # creates unexpected merge commit: 'Merge branch 'feature' of origin'
✓ Fixed code
git reset --hard HEAD~1  # undo merge commit
git config pull.rebase true
git pull  # now rebases instead of merging

Configuring pull.rebase true makes git pull replay your local commits on top of the remote changes, producing a linear history without merge commits.

How to diagnose

  • Run git log --oneline --graph -5 to see the merge commit and understand the divergence that caused it

  • Check git config pull.rebase — if unset or false, git pull uses merge by default

  • Run git log --oneline HEAD..origin/branch and git log --oneline origin/branch..HEAD to see both sides of the divergence

How to fix

  • Undo the merge commit with git reset --hard HEAD~1 and re-pull with git pull --rebase to get a linear history

  • Configure git to always rebase on pull with git config --global pull.rebase true to avoid future merge commits

  • If the merge commit is already pushed and acceptable, leave it — but switch to rebase for future pulls to keep history linear

How to prevent

  • Set git config --global pull.rebase true to make git pull use rebase by default for a cleaner linear history

  • Use git pull --ff-only to refuse non-fast-forward pulls, forcing you to explicitly decide how to integrate divergent changes

Related Resources

Related Glossary

Related Lessons

← Back to language