I create lots of WIP commits while I work. The code ends up in master, but the WIP commits don’t.

Before a branch is merged, I rewrite its history into a handful of small, deliberate commits that each tell part of the story: “INV-482 Extract due date calculation into PaymentTerms”, then “INV-482 Fix due date calculation for invoices issued in December”.

My branches are short-lived: most live for a few hours or a couple of days, and almost none last longer than a week before they’re merged into master and released. It’s effectively scaled trunk-based development, where I use my working branch as a private scratchpad and tidy it before creating the pull request.

In this article I’ll walk through my workflow, the git commands involved, and why tidying up commits before review has been worth it over the last 15+ years of doing so.

The workflow at a glance

Git graph: WIP commits on a branch off origin/master, rewritten into a few clear commits and merged back

  1. git fetch to make sure you’re up to date with origin
  2. Create your feature/bugfix branch from origin/master, named after the ticket that you’re working on
  3. Create WIP/checkpoint commits freely and regularly. Push to your working branch as a backup
  4. Rebase onto the latest origin/master regularly, reordering, fixing up, and squashing your WIP commits as needed
  5. Optionally open a draft “preview PR” early to check that you’re on the right track or get early feedback
  6. When ready for review, open the PR (or mark the draft PR as ready) with a few clear commits, to be merged into origin/master and deployed in the next release

Step by step

The running example is an orders and invoicing app where invoices due in the following month get the wrong due date, so customers receive overdue notices too early.

Branch off the latest origin/master

git fetch origin
git checkout -b feature/INV-482 origin/master

I branch from origin/master rather than my local master, which is easy to let drift. Forget to pull, or accidentally commit to it, and the new branch starts from the wrong place. After a fetch, origin/master is what’s actually on the server.

I name the branch after the work item, like feature/INV-482. That makes it obvious what the branch is for and keeps it tied to the ticket. If there’s no ticket, I name it after the feature, like feature/december-invoice-due-date.

Commit WIP early and often

Until the PR, commits are checkpoints, not permanent history. I commit whenever something works, before I try something risky, or when I’m about to take a break, and the messages at this stage are just notes to myself:

git commit -m "wip due date fixes"
git commit -m "add due date test"
git commit -m "ref due date test"
git commit -m "wip refactor"

This gives me cheap undos: if I change my mind, I reset to an earlier checkpoint.

I also push to my remote branch regularly as a backup, because a branch that exists only on my laptop is one dead SSD or bad system update away from being lost. Once I’ve rebased, a force push is required, so I prefix the branch with a + to force push to that one branch and nothing else (more on force pushing in the tips below):

# Ordinary backup push
git push origin feature/INV-482  

# After rebasing locally
git push origin +feature/INV-482 

On my own projects and in small teams, I push straight to origin. In larger teams, I push to my own fork, so WIP branches and force pushes don’t clutter the shared repo.

Keep up with master by rebasing, not merging

While I work, other people are merging into master. I’ll pull their changes in with a rebase, so my commits always sit on top of the latest master, with no merge commits cluttering the history:

git fetch origin
git rebase origin/master

Because the branch is short-lived and my changes are fresh in my mind, conflicts are rare, and almost always trivial to resolve.

Use preview PRs to get early feedback

For more complex changes, I’ll often open a draft PR while it’s still a collection of commits, and send it to a reviewer with “is this looking like the right general strategy?” or “something like this?”. I call these preview PRs.

The reviewer skims the approach, or focuses on a couple of specific areas, rather than every line. If I’ve misunderstood something, or picked the wrong design, I find out early rather than after days of work. A draft PR can’t be merged until it’s marked ready, and the branch is still mine, so I carry on adding WIP commits and rebasing as normal.

Rewrite the WIP commits to tell a story

When the work is done, I open an interactive rebase over the branch:

git rebase -i origin/master

Git lists my commits, oldest first, as the raw history of checkpoints:

pick a1b2c3d wip due date fixes
pick d4e5f6a add due date test
pick 7a8b9c0 due date working
pick 1d2e3f4 ref due date test
pick 5a6b7c8 wip refactor
pick 9d0e1f2 fix typo

I edit the list into one which I want to become permanent git history. The refactor moves to the top with the typo fix folded into it, the rest folds into the due date fix, and r (reword) opens an editor so I can write a proper message for each commit that remains:

r 5a6b7c8 wip refactor
f 9d0e1f2 fix typo
r a1b2c3d wip due date fixes
f d4e5f6a add due date test
f 7a8b9c0 due date working
f 1d2e3f4 ref due date test

The result is two commits:

INV-482 Extract due date calculation into PaymentTerms
INV-482 Fix due date calculation for invoices issued in December

Reordering can cause conflicts, especially when a commit moves ahead of work it was originally written on top of. I resolve them as usual, or if it gets messy, git rebase --abort and try a simpler order.

Small, safe changes go first

When I reorder, small, low-risk commits go to the start of the branch, and the bigger change goes last:

  • Incidental tidy-ups: a stale comment or confusing name I noticed along the way gets its own commit.
  • Preparatory refactors: a refactor that makes the bigger change easier (sometimes called “tidy-first”) goes ahead of it, even if I only realised I needed it halfway through.

The reviewer can scan the tidy-ups quickly. The functional change carries less noise, and if the big change drags on, the early commits can go out in their own PR.

Push and open the PR, or mark the preview ready

Since I’ve rewritten history, it’s a force push to the same branch:

git push origin +feature/INV-482

Then I open the PR, or mark the preview PR as ready for review.

While I squash during interactive rebase, I never squash-merge: the commits are written to be part of the history, and squash-merge would mash all of that up. Depending on the project’s convention, I use either a merge commit, or rebase-and-merge. Either way, my commits end up in master with history intact.

Let tests and CI gate the merge

Nothing merges into master until CI passes on the PR. That’s what keeps master releasable.

Every bug fix comes with a regression test. For the due date bug, the test issues an invoice on the 15th of December for the 20th of the following month, checking that it’s due on 20th of January the following year. The test fails without the fix, and passes with it, then remains in the test suite, so that the bug doesn’t quietly come back due to a change in future. The test remains in the same commit as the fix. Reverting that commit takes the test out along with the functionality change.

CI runs on every push to the PR, force pushes and preview PRs included, so I find out early if the WIP has broken something unrelated.

Branch protection enforces PR checks: Alongside blocking force pushes to master, I turn on two rules:

  • Require status checks to pass before merging, so that a red build can’t be merged by accident.
  • Require branches to be up to date before merging, so that tests have run against the latest origin/master, not a version from two days ago. With a rebase workflow, this is cheap: rebase, force push, and CI runs again.

Why several commits, not one big squash?

Many teams squash every PR into a single commit. That’s better than merging forty WIP commits, but it throws away structure: a PR often contains more than one idea, and each idea deserves its own commit.

  • Review is easier: a reviewer reads the refactor commits expecting no behavior change, then focuses on the commits that do change behavior.
  • git blame and git bisect are much more precise: they land on small commits with clear purpose, not a big mixed one.
  • Reverts are surgical: if the fix is wrong, I revert just that commit, and keep the refactors and tidy-ups.

The general rule: each commit is atomic, reasonably small, and about one topic. A topic isn’t the same as a single change. One commit might fix a bunch of outdated comments, and another might change how invoice PDFs are generated across several files. What matters is that each commit is scoped to one task, explains why in its message, leaves the build and tests passing, and reads as the next step in the story.

Writing the commit messages

I use a ticket-first subject line, followed by a body written in the style of the Linux kernel’s commit message guidance. It’s been refined over decades by people who read a lot of history, and it works well for any project:

INV-482 Fix due date calculation for invoices issued in December

Invoices on "20th of the following month" terms moved to the
next month, but kept the year that they were issued, so an
invoice issued on 15th of December 2025 was being set to due
on 20th of January 2025, resulting in an invoice that was overdue
as soon as it was sent.

Roll the year over when the following month is January. This also
fixes the early payment reminders reported in INV-455, which use
the same calculation.

Co-authored-by: John Smith <[email protected]>

For a single-commit PR, GitHub fills the PR description from the commit message. For a multi-commit PR, I write a short overview and either summarise the commits or just say “see individual commits”. The reviewer can review the whole diff, or go commit by commit, and the detail stays in the commit messages long after the PR is forgotten.

This is scaled trunk-based development

Trunk-based development comes in several flavors. “Scaled trunk-based development” uses short-lived feature branches that are reviewed in a PR and merged into master once review and CI pass. Master is the only long-lived branch.

The key is how short-lived. Mine usually last hours to a few days, almost never more than a week. That keeps what trunk-based development is after: master stays releasable, rebasing every day or so keeps me close to what the rest of the team is doing, and no branch drifts away from master for weeks. If work is too big to finish within a week, it’s usually a sign to split it into smaller PRs or put it behind a feature flag.

Tips and gotchas

Fold fixes in with fixup commits. If I spot a typo in an earlier commit, I add a fixup commit that targets it, and fixup into the right place during the next interactive rebase.

Once a reviewer has commented though, a force push makes it hard for them to see what changed since they last looked. So during review, I push fixup commits on top, and only once the review is done do I fold each one into the commit where it belongs (or keep it in its own commit if it stands alone, like a new validation), and push the final history.

Force push only to branches you own, and always name the branch. A bare git push --force pushes whatever your config says to push, which on some setups means every branch, master included. git push origin +feature/INV-482 forces exactly one branch. I only ever rewrite branches that nobody else is pulling from or pushing to. On a shared branch, I don’t rebase or force push at all.

Lock master against force pushes. Master should only ever be merged into. Branch protection on your git host stops anyone force pushing to master or deleting it, and requires changes to land through a PR.

Use the reflog as a safety net. If a rebase goes badly wrong, nothing is lost: git reflog shows where the branch was before, and git reset --hard <sha> puts it back.

Wrapping up

The whole workflow is essentially this: branch from origin/master, create WIP commits as often as you like, rebase to keep up, then rewrite the branch into a few clear commits before review.

You get the freedom of a scratchpad while you work, and a history on master that reads like a changelog, for the cost of a few minutes in an interactive rebase per branch.

If you work differently, or have tricks for keeping commit history readable, please get in touch!