Calculate how many commits two Git branches have diverged from a common ancestor.
Divergence quantifies how far two branch tips have drifted apart. Formula: divergence = commits_ahead + commits_behind, as reported by `git rev-list --left-right --count base...branch`. A branch with many commits behind is at higher risk of conflicting with recent base changes; combining divergence with the count of files touched on both sides gives a rough merge complexity score.
Total divergence
divergence = commits_ahead + commits_behind
Merge complexity score
complexity_score = clamp(base_score_from_divergence + files_touched_by_both × 1.5, 0, 100)
Run `git rev-list --left-right --count origin/main...my-branch` — it prints two numbers: commits only on main (behind) and commits only on my-branch (ahead).
Being behind means the base has moved on without you, increasing the odds that files you're touching have also changed upstream — the primary source of merge conflicts, not raw commit count.
Many teams treat 20-50 commits behind as a signal to rebase or merge from base soon; beyond that, conflict risk and review complexity both climb sharply.
No — divergence measures drift over time, while actual conflict risk depends on whether the same files/lines were touched on both sides (see the merge conflict probability calculator).