Skip to content

Handling Divergent Branches in Git (Blackcairn Infra)

What happened

When running git pull, Git reported:

You have divergent branches and need to specify how to reconcile them.

This means: - Your local main branch has commits that are not on origin/main - The remote origin/main branch also has new commits - Git refuses to guess how you want to combine them

This behaviour is standard in Git 2.27+.


For this repository, the preferred strategy is rebase.

Why: - Keeps a clean, linear history - Avoids unnecessary merge commits - Works well with GitHub as the source of truth - Ideal for infra / GitOps-style repositories


One-time fix (per repository)

Run:

git config pull.rebase true
git pull

This will: - Fetch origin/main - Replay your local commits on top of it - Leave you with a tidy commit history


Alternative strategies

Merge (explicit but noisy)

git config pull.rebase false
git pull

Creates a merge commit. Safe, but clutters history.

Fast-forward only (very strict)

git config pull.ff only
git pull

Fails unless a clean fast-forward is possible. Best for CI, less friendly for day-to-day work.


Setting a global default (optional)

To always rebase on pull for all repositories:

git config --global pull.rebase true

You can still override per pull:

git pull --no-rebase
git pull --rebase

After pulling: sanity checks

git status
git log --oneline --decorate -5

You should see: - HEAD -> main - No divergence warnings - Your commits sitting on top of origin/main


Summary

  • Divergent branches are normal
  • Git now requires an explicit strategy
  • Rebase is recommended for Blackcairn Infra
  • Set it once and forget about it