Workflows

Prepare commit history before opening a pull request

Build a stable pre-PR routine around syncing, commit cleanup, risk checks, and review-friendly history.

Who This Is For
  • Teams turning commands into repeatable routines
  • Readers who need sequencing, branch, and sync discipline
Prerequisites
  • Basic understanding of fetch, pull, push, and branches
  • A sense of how and why branches diverge
Common Risks
  • Copying a workflow without checking branch state
  • Choosing the wrong integration path on shared branches

Pre-PR cleanup is not about making history look clever. It is about making review easier, rollback cleaner, and future debugging less painful.
The best pull requests often feel clear because the history was shaped before review started.

A stable pre-PR cleanup sequenceSync first, clean obvious noise, verify commit boundaries, then confirm there is no shared-history risk.
Confirm first
latest main statelocal commit listworking tree boundaries
A good PR should give
clear intentclean diff scopecontrolled history risk
History cleanup is not performance art. It is preparation for better review.

Why pre-PR cleanup matters

Many reviews feel harder than they should because the history is noisy:

  • temporary fixup commits remain in place
  • commit titles do not express intent clearly
  • unrelated changes are mixed together
  • the branch is still based on stale main-line state

Once that noise enters review, reviewers spend attention reconstructing your intent instead of evaluating the change itself.

A practical order

1. Sync with the current main line

git fetch origin
git rebase origin/main

If your team prefers merge here, that can still be valid.
The essential point is not “always rebase.” It is “understand the relationship between this branch and main before you publish it.”

2. Remove obvious noise commits

Typical noise includes:

  • fix typo
  • oops
  • review fix
  • “trying to make CI green” style commits

If those can be consolidated safely before review, they usually should be.

3. Re-check commit messages and change boundaries

Ask:

  • does each commit represent one understandable intent
  • do the commit boundaries match the code intent
  • were formatting, renaming, and feature work mixed together unnecessarily

4. Confirm there is no shared-history risk

If other people already depend on the current branch history, rebase and commit rewriting stop being simple cleanup and start becoming coordination changes.

A conservative flow

git fetch origin
git rebase origin/main
git log --oneline --decorate -n 10
git diff --stat origin/main...

This helps answer:

  • whether the base is current
  • whether recent commits still contain noise
  • whether the visible diff matches the story the PR is about to tell

Four things worth checking

  1. whether obvious fixup-style commits can still be cleaned
  2. whether each commit title carries an understandable intent
  3. whether unrelated changes were mixed into the branch
  4. whether this history may already be shared with someone else

When not cleaning further is actually safer

Not every moment is the right moment to rewrite history. Be more conservative when:

  • the branch is already shared
  • review is already active and comments depend on current commit structure
  • the team discourages rewriting history during review
  • shipping speed matters more than further polish

History cleanup is a tool, not a moral rule.

Do not heavily rewrite history once review context depends on it

If reviewers already commented against the current commit structure, aggressive rebasing can invalidate discussion context quickly. Pre-review cleanup is high value. Mid-review cleanup should be deliberate and limited.

Common mistakes

Assuming “fewer commits” automatically means “better PR”

The goal is not fewer commits. The goal is clearer intent.

Rewriting titles but not commit boundaries

A polished title cannot rescue a commit that still mixes three unrelated changes.

Cleaning history before checking branch freshness

If the base is stale, you may end up reorganizing the branch twice.

Use these four questions before opening a PR
  1. Can a reviewer infer intent from the commit titles?
  2. Does the branch still contain obvious noise commits?
  3. Does the diff scope match the PR story?
  4. Will more cleanup now affect already-shared history?

One principle

Commit history is written for future review, rollback, and debugging, not just for Git itself.