When to Rebase PRs

lesson workflow active workflow/when-to-rebase-prs.md View on GitHub

When to Rebase PRs

Rule

Only rebase PRs when there are merge conflicts, not just because they're behind master.

Context

When reviewing PR status and considering whether to rebase them onto latest master.

Detection

Observable signals indicating unnecessary rebase:

Common pattern: See "⟳ 5 behind" → immediately rebase → no actual conflict existed

Pattern

Check for conflicts first, not just behind count:

# Wrong: rebase based on behind count
gh pr view <url>  # Shows "⟳ 5 behind"
cd /path/to/repo && git pull && git rebase origin/master
# Wastes time if no conflicts exist

# Correct: check mergeable status first
gh pr view <url>  # Check output
# - mergeable=true, state=clean → No rebase needed ✓
# - mergeable=false, state=dirty → Rebase to resolve conflicts
# - "⚠ CONFLICTS" indicator → Action needed

# Only rebase when conflicts exist
if [ "$mergeable" == "false" ]; then
    cd /path/to/repo && git rebase origin/master
fi

Decision matrix:

Outcome

Following this pattern leads to:

Benefits demonstrated:

Related

Match Keywords

commits behind ⟳ behind ⚠ CONFLICTS mergeable=false rebase based on behind count rebasing without checking for conflicts