Short-Lived Branches as a Discipline

A real branch that lived far too long. Measure exactly how far it drifted, in both directions.

Somewhere in the real project history, feature/old-refactor was branched off, worked on for a while, and then genuinely forgotten. Master kept moving. The branch kept its own real commits too. Neither side knows about the other's recent work.\n\nBefore writing any judgment about what to do next, the real, measurable facts come first: exactly how far ahead, and exactly how far behind, has this branch actually drifted? git rev-list answers both numbers at once, in one real command.

Both Numbers, One Real Command

git fetch origin
git rev-list --left-right --count master...origin/feature/old-refactor

The triple-dot range compares both directions at once: the first number is commits master has that the branch lacks, the second is commits the branch has that master lacks.

Seeing Exactly What's on Each Side

git log --oneline master..origin/feature/old-refactor
git log --oneline origin/feature/old-refactor..master

Real, specific commits, not just counts โ€” genuinely useful for judging how bad the eventual merge or rebase will be.

Why This Is Worse Than One Number Alone

A branch that is only "6 commits behind" is a simple catch-up. A branch that is only "6 commits ahead" is a normal feature in progress. A branch that is genuinely BOTH means every one of its own real commits was written against a version of the shared files that no longer exists โ€” the eventual merge has to reconcile real, independent changes on both sides at once, not just catch up one direction.

git rev-list --left-right --count a...b

Reports two real numbers at once: commits reachable from a but not b, and commits reachable from b but not a. Confirmed directly in this lab producing "6\t6" โ€” six commits master has that the branch lacks, six the branch has that master lacks.

๐Ÿ“ Measure the Real Divergence

Get both real numbers โ€” ahead and behind โ€” in a single command.

cd ~/team-recipes && git fetch origin
cd ~/team-recipes && git rev-list --left-right --count master...origin/feature/old-refactor

student@lab:~$ cd ~/team-recipes && git fetch origin student@lab:~$ cd ~/team-recipes && git rev-list --left-right --count master...origin/feature/old-refactor 6 6

๐Ÿ” See Exactly What Is on Each Side

List the specific real commits each side has that the other lacks.

cd ~/team-recipes && git log --oneline master..origin/feature/old-refactor
cd ~/team-recipes && git log --oneline origin/feature/old-refactor..master

student@lab:~$ cd ~/team-recipes && git log --oneline master..origin/feature/old-refactor 8f80026 (origin/feature/old-refactor, feature/old-refactor) WIP refactor attempt 6 6a704fb WIP refactor attempt 5 3696a93 WIP refactor attempt 4 714f20c WIP refactor attempt 3 844775d WIP refactor attempt 2 8d74197 WIP refactor attempt 1 student@lab:~$ cd ~/team-recipes && git log --oneline origin/feature/old-refactor..master 02d28bb (HEAD -> master, origin/master, origin/HEAD) Merge pull request: pantry checklist bc673fe Add pantry checklist items for quick meals 18a19e6 Add basic staples to pantry checklist c674e3e Start pantry checklist c09803f Add trail mix recipe 4ea9305 Add green smoothie recipe

Lab 2.2.2 complete. A real branch's exact, measured divergence โ€” not a guess, a real diagnosis:\n\n\n Real divergence measured : โœ… 6 ahead, 6 behind\n Exact commits on each side listed : โœ… confirmed\n

Enable JavaScript to run the live terminal and track your progress.