Break a large commit into a reviewable stack of small atomic commits
Split a large commit into multiple smaller, atomic commits. Target commit defaults to HEAD if not specified.
Check branchless init:
if [ ! -d ".git/branchless" ]; then git branchless init; fi
Identify the target commit. If $ARGUMENTS is provided, use it.
Otherwise default to HEAD.
Analyze the commit to understand what it contains:
git show --stat <commit>
git show <commit>
Read the full diff. Identify logical groups:
Documentation belongs with the feature it documents, not as a separate split. Dependencies and config files go in the commit that first uses them.
Propose a split plan to the user. For each proposed commit:
Wait for user approval before proceeding.
Perform the split using interactive rebase:
git rebase -i <commit>^
Mark the target commit as edit, then:
git reset HEAD^
This unwinds the commit but keeps all changes in the working tree.
Stage and commit each group in the agreed order:
git add -p # or git add <specific-files>
git commit -m "descriptive message for this group"
Repeat for each logical group. Each commit must:
Complete the rebase:
git rebase --continue
Restack if there are downstream commits:
git restack
Verify the result:
git sl
Show the user the new stack. If a test command is available, run tests across the new commits:
git test run -x '<test-command>' 'stack()'
If the user wants to restructure multiple commits (not just split one):
git reset --soft main — uncommit everything, keep changesgit restore --staged . — unstage to working treegit add -pgit sl and testsgit add -p to split
hunks within the file