Skip to content

git commit --fixup / --squash + rebase --autosquash: PR Review Fixup Workflow ​

A review comes back: "rename that function", "fix that typo", "this needs a comment". You fix it and commit. Now you have an ugly history with "fix typo", "address review feedback", "actually fix the fix". The fixup workflow lets you mark each correction against the original commit so rebase --autosquash can fold them in automatically. You get bisect-safe, atomic history without rewriting the todo list by hand.

How it works ​

git commit --fixup=<SHA> creates a commit whose message starts with fixup! <original-subject>. The SHA tells Git which commit this fixup belongs to. Git stores the target SHA in the commit message body as fixup! target <SHA>.

git commit --squash=<SHA> works the same way but its message keeps squash! <original-subject> and preserves the message text for further editing during the rebase.

When you run git rebase -i --autosquash, Git scans the todo list for fixup! and squash! commits. It reorders the list so each fixup lands immediately after its target, marked as fixup or squash respectively. The rebase runs without further interaction unless there's a conflict.

bash
# Mark a commit for fixup
git commit --fixup=abc1234

# Or fixup the current HEAD
git commit --fixup=amend:
git commit --amend --no-edit   # same thing, different path

# Let rebase arrange everything
git rebase -i --autosquash HEAD~5

# With the config on, plain -i also autosquashes
git config rebase.autoSquash true
git rebase -i HEAD~5

Setting up ​

The config rebase.autoSquash is the one toggle you need. Set it globally and every git rebase -i will autosquash without the --autosquash flag.

bash
git config --global rebase.autoSquash true

Alternative values:

ValueBehaviour
trueRearranges fixup/squash commits automatically, runs the rebase.
logLogs the proposed reordering to stderr but still runs it. Useful for auditing what happened.
falseDefault. Only autosquashes when --autosquash is passed.

The PR review cycle in practice ​

This is where the workflow earns its keep. A typical review cycle looks like:

  1. Push a feature branch with 5 clean commits.
  2. Reviewer asks for 3 changes spanning 3 different commits.
  3. You make each change and git commit --fixup=<SHA> targeting the commit each change belongs in.
  4. Reviewer approves.
  5. Run git rebase -i --autosquash HEAD~8 or --onto main.
  6. The fixups collapse into their targets. History is 5 atomic commits again.
  7. Push the clean branch (force push).

No manual todo list editing. No "fix review feedback" commits in the permanent record. No thinking about which commit goes where.

bash
# Workflow as a one-liner alias
git config --global alias.squash-branch \
  '!git rebase -i --autosquash --onto $(git merge-base HEAD @{upstream})'

CI gate: reject branches with fixup commits ​

A branch with fixup commits should never merge. The PR must be squashed first. A CI check catches it:

bash
# In CI, reference the target branch
git log --oneline --grep="^fixup!" origin/main..HEAD
if [ $? -eq 0 ]; then
  echo "Branch contains fixup! commits. Run rebase --autosquash before merging."
  exit 1
fi

Or check for both fixup and squash:

bash
! git log --oneline --grep="^(fixup|squash)!" origin/main..HEAD | grep .

For a server-side pre-receive hook:

bash
#!/bin/bash
# hooks/pre-receive — reject pushes with fixup commits
while read oldsha newsha ref; do
  if [ "$ref" = "refs/heads/main" ] || [[ "$ref" = refs/heads/release/* ]]; then
    commits=$(git rev-list "$oldsha".."$newsha" 2>/dev/null)
    fixups=$(git log --no-walk --oneline --grep="^fixup!" $commits 2>/dev/null)
    if [ -n "$fixups" ]; then
      echo "Rejected: protected branch contains fixup! commits. Squash first."
      exit 1
    fi
  fi
done

Fixup shorthand for amend: ​

git commit --fixup=amend: targets HEAD without typing a SHA. This is the fastest way to fold a change into the most recent commit:

bash
# Make a change, then
git add -p
git commit --fixup=amend:

git commit --squash=amend: does the same but keeps the message for editing.

Rebase --autostash with autosquash ​

If you have uncommitted changes when rebasing, --autostash stashes them, runs the rebase, then unstashes:

bash
git rebase -i --autosquash --autostash HEAD~5

Combine with rebase.autoSquash so the flag is only --autostash:

bash
git config rebase.autoSquash true
git rebase -i --autostash HEAD~5

--update-refs and fixup commits ​

When rebasing a stack of branches (each branch building on the previous), --update-refs moves branch refs to track their rebased versions. This works with autosquash:

bash
git rebase -i --autosquash --update-refs HEAD~10

The fixup commits get folded into their targets, and dependent branches get moved to point at the new versions.

Verification with range-diff ​

After an autosquash rebase, validate that no unintended changes were introduced. Capture the branch tip before and after:

bash
# Before rebase
git rev-parse HEAD > /tmp/pre-squash

# After rebase
git range-diff $(cat /tmp/pre-squash)..$(cat /tmp/pre-squash) HEAD..HEAD

Or compare against the upstream:

bash
git range-diff @{upstream}...HEAD@{1} @{upstream}...HEAD

range-diff pairs commits on the old side with the new side and shows only the patches that actually changed. A clean squash produces identical patches; you see zero diff lines.

Pitfalls ​

Fixup commits in git log --grep output. The fixup! message prefix leaks into every grep. Filter them out:

bash
git log --oneline --grep="feature" --invert-grep --grep="^fixup!"

Conflicts during autosquash. A fixup commit must apply cleanly on top of its target. If another fixup (or a sibling commit) changes the same code, you get a conflict during the rebase. Fix it, then git rebase --continue.

Forgetting to autosquash before pushing. The fixup commits are real commits with real SHAs. If you push them, they're on the remote. The CI gate above catches this, but you can also run a local hook:

bash
# .git/hooks/pre-push
#!/bin/bash
commits=$(git log --oneline --grep="^fixup!" HEAD)
if [ -n "$commits" ]; then
  echo "Fixup commits detected. Run rebase --autosquash first."
  exit 1
fi

Multiple fixup commits aimed at the same target. rebase -i --autosquash orders them chronologically. If the order matters (one fixup depends on another), do a separate rebase for the dependent fixups or reorder in the editor.

rebase.autoSquash with shared branches. If you work on a shared branch and someone else rebases with autosquash enabled, the reordering might surprise them. Autosquash is safest on private feature branches. Don't enable it globally if you regularly rebase shared history.

Fixup amend: with a divergent index. git commit --fixup=amend: commits the working tree as it is. If the index doesn't match the working tree (e.g., git add -p staged part of a file), the fixup commits the full working tree state, not just the index. Run git add -A first or use git commit --fixup=amend: --include to only commit staged changes.

Comparison with other approaches ​

ApproachProsCons
git commit --fixup + autosquashZero-friction, automated, bisect-safeRequires a rebase. One extra step before push.
Manual rebase -iFull controlMust edit the todo list. Easy to miss a reorder.
Squash merge on PR closeOne clickBuried history: the individual commits vanish. Bad for bisect.
git commit --amendFast, single commandOnly works on HEAD. Breaks pushed branches immediately.
Cherry-pick + resetSelectiveMore commands, more steps. Easy to mess up.

Debugging: what autosquash actually reordered ​

Run the rebase in dry-run mode to see the proposed reordering without executing:

bash
# Git doesn't have a native dry-run for rebase, but you can inspect the todo:
GIT_SEQUENCE_EDITOR=cat git rebase -i --autosquash HEAD~5

This prints the todo list and exits. Look for fixup <SHA> <original-subject> lines placed directly under their target.

See also ​

  • docs/devops-workflows/git-rebase-interactive.md — rebase fundamentals
  • docs/devops-workflows/git-range-diff.md — verifying rebase correctness
  • docs/devops-workflows/git-push-safety.md — force-push protections for rebased branches
  • docs/devops-workflows/git-cherry-pick.md — alternative selective commit pattern
  • docs/recipes/fixup-autosquash-quick.md — cheat sheet
  • scripts/fixup-autosquash-manage.sh — automation script

Git Master — Git Reference for Every Skill Level