GitButler CLI Skill
Use GitButler CLI (but) as the default version-control interface.
Start Here
Choose the first command by task:
# Selected dirty files/hunks:
but diff
# Commit order, branch layout, conflict overview:
but status
# Per-commit file details, amend/split details:
but status -fv
For "commit just/only/specific changes on a new branch", use the fast path:
but diff
but commit <branch> -c -m "<msg>" --changes <id>,<id>
but commit <branch> -c ... --changes ... creates the branch and prints the resulting workspace state. Do not run a separate but branch new, staging command, status command, or verification diff unless the returned output lacks information you need.
--changes (or -p) takes comma-separated file or hunk IDs from but diff / but status -fv. A hunk ID is written <file-id>:<hunk-id> (e.g. qs:5, copied from but diff) — the part after the colon is the hunk's ID, not a line range (qs:16-40 is invalid). Do not invent flags like --hunk / --hunks / --ids, pass a line range, or pass the IDs as positional arguments.
The first token on each status line is that line's ID — pass it to commands as-is. Commit IDs are stable change IDs that survive history edits (amend, squash, move, uncommit, reword); commits without a change ID (e.g. upstream-only) lead with a sha prefix instead, which goes stale after history edits. The (sha …) shown on verbose commit lines is informational — do not pass it to commands. CLI IDs may be a single character when unambiguous; copy them exactly from command output. Longer unambiguous prefixes also work.
Non-Negotiable Rules
- Use
but for all write operations. Never run git add, git commit, git push, git checkout, git merge, git rebase, git stash, or git cherry-pick. If the user says a git write command, translate it to but and run that. Exceptions: git add -- <path> to mark a conflicted uncommitted file resolved (see "Conflicts in uncommitted files"), and a worktree-local Git commit when reports that linked worktrees are unsupported. Never run from a linked worktree.
Choose Inspection By Task
Start with the narrowest inspection that answers the task. Avoid ritual status checks.
# Selected dirty files/hunks:
but diff
# Commit order, branch/stack placement, conflict overview:
but status
# File/hunk IDs, per-commit files, amend/split details:
but status -fv
# Details for one known branch or commit:
but show <id>
Do not run plain but status and then but status -fv unless the compact output lacks file/hunk details needed for the task.
Perform mutations with IDs from diff, status, status -fv, or show:
but <mutation> ...
Command Patterns
- Commit:
but commit <branch> -m "<msg>" --changes <id>,<id>
- Several commits from one diff: chain
but commit calls - but commit <branch> -m "<msg>" --changes <id>,<id> && but commit <branch> -m "<msg>" --changes <id>,<id> (commits stack oldest-first in the order you write them — first call is oldest; file/hunk IDs from the initial output generally remain usable; refresh if an ID stops resolving)
but commit -a is accepted as a no-op compatibility flag; GitButler already includes uncommitted changes by default.
- Commit + create branch:
but commit <branch> -c -m "<msg>" --changes <id>
- Commit at a specific history position:
but commit <branch> -m "<msg>" --changes <id>,<id> --before <commit-or-branch-id> or --after <commit-or-branch-id>
- Amend:
but amend <commit-id> --changes <file-or-hunk-id>,<file-or-hunk-id>
Task Recipes
Update workspace from main
For "get latest from main", "update/sync this workspace", or "pull main":
but status -fv
but pull --check
- If clean,
but pull
but status -fv
but pull updates applied branches onto the latest target branch (usually
main). Do not use raw git pull or git rebase.
Commit selected files or hunks
but diff — use this first for selective dirty commits. It shows file and hunk IDs for uncommitted changes.
- Use file IDs when whole files belong in the commit. When only part of a file belongs, commit its hunks by ID —
<file-id>:<hunk-id> from but diff (e.g. qs:5), not the whole file ID and not a line range. Do not run plain but status first.
- For a new branch, use one command:
but commit <branch> -c -m "<msg>" --changes <id1>,<id2>.
For an existing branch, omit -c: but commit <branch> -m "<msg>" --changes <id1>,<id2>.
Omit IDs you don't want committed.
Creating a new branch with -c does not require a prior but branch or .
Edge case: if wanted and unwanted edits are in the same diff hunk, GitButler cannot split that hunk by ID. Only when the task requires keeping part of that hunk uncommitted, temporarily edit the working tree to isolate the wanted lines, commit with --changes, then restore the leftover lines so they remain uncommitted.
Amend into existing commit
but status -fv (or but show <branch-id>)
- Locate file/hunk IDs and target commit ID.
but amend <commit-id> --changes <file-or-hunk-id>,<file-or-hunk-id>; use one command for multiple files/hunks that belong in the same commit. To amend into several different commits, run the amends in sequence — change-ID refs from one status read survive each amend, but take fresh refs from the returned status whenever a ref is sha-based or #N-suffixed.
Split an existing commit
Use this when an existing commit should be replaced by selected smaller commits.
but status -fv when you need the source commit, branch name, or placement anchor.
but uncommit <source-commit-id> --diff to expose that commit's changes as uncommitted changes and print committable file/hunk IDs.
- Pick replacement commit contents from the dirty diff printed by
but uncommit --diff, not from the old committed diff.
- Create the replacement commits in the requested order, oldest first, by chaining
but commit calls (file/hunk IDs from the diff stay usable across commits):
but commit <branch> -m "<message 1>" --changes <id>,<id> && but commit <branch> -m "<message 2>" --changes <id>,<id>
Each new commit goes to the TOP of the stack. So if you split a commit that had other commits above it, the replacements are now sitting above those preserved commits.
- If any commit must stay ABOVE the replacements (a preserved top commit), put it back on top instead of fighting anchors. Do not anchor the replacements with
--before <top>/--after <top>: a sha-based or #N-suffixed anchor goes stale as and each insert rewrite history (and just puts commits on top of the branch). Instead, take the preserved commit's ref from the workspace state the last printed, then to lift it back to the top/newest (for several preserved commits, list every one, oldest first: ).
Reorder commits
but move supports both commit reordering and branch stack operations. Use commit IDs when reordering commits.
but status displays commits newest/top first, while task specs often list history oldest to newest. Use but status -fv only if you also need file-level details.
but status
but move <source-commit-id> <target-commit-id> places source immediately before target in oldest-to-newest history. In but status, source appears directly below target.
but move <source-commit-id> <target-commit-id> --after places source immediately after target in oldest-to-newest history. In but status, source appears directly above target.
but move <source-commit-id> <branch-name-or-id> moves source to branch top/newest.
but move <source-commit-id>,<source-commit-id> <target-commit-id> moves multiple commit sources together. Multi-source moves accept comma-separated commit IDs only, not branch names.
For explicit final-order tasks, run but status once to get commit IDs. If the task names an adjacent commit block, do not sort the whole branch or move block members one by one: preserve the block's internal oldest-to-newest order, find the commit that should immediately follow the block in the requested oldest-to-newest order, then run one block move: but move <oldest-block-id>,<newest-block-id> <following-commit-id>. After a successful block move, stop if the returned status shows the requested order; do not move the anchor or any member of that block again.
For other explicit reorders, translate the requested order into the newest-to-oldest order shown by but status, then make the smallest set of moves. Prefer the default before/below form because it matches the status display: but move <source> <newer-neighbor> places source directly below its newer neighbor. Use a branch target only when a commit must become top/newest, and use --after only when it clearly avoids extra moves.
Squash commits
Use this when multiple existing commits should become one commit.
but status to get commit IDs and current order. Use but status -fv only if you also need per-commit file details.
- Put the result/target commit last:
but squash <source-commit-id> [<source-commit-id>...] <target-commit-id> -m "<new message>".
- For multiple independent squash groups, prefer newer/top groups first; change-ID refs from one status read stay valid across squashes (the target keeps its ref), so the groups may run in sequence — take fresh refs from the returned status only when a ref is sha-based or
#N-suffixed.
- After the final squash, stop if returned status shows the requested history; do not run
--help, status, or status -fv only to reconfirm.
Stack existing branches
To make one existing branch depend on (stack on top of) another, use top-level move:
but move feature/frontend feature/backend
This moves the frontend branch on top of the backend branch in one step.
DO NOT use uncommit + branch delete + branch new -a to stack existing branches. That approach fails because git branch names persist even after but branch delete. Always use but move <branch> <target-branch>.
To unstack (make a stacked branch independent again):
but move feature/logging zz
Note: branch stack/tear-off operations use branch names (like feature/frontend) or branch CLI IDs, while commit reordering uses commit IDs (like nn). Do NOT use but undo to unstack — it may revert more than intended and lose commits.
Create or manage pull requests
but pr new <branch-id> pushes the branch and creates a pull request in one step. Do not run but push first. Agents must provide -F pr_message.txt, -t, or -m with real newline characters (zsh/bash: -m $'Title\n\nBody') so the command does not open an editor. If forge auth is missing, run but config forge auth.
For independent, unstacked branches, another forge tool may be okay if the user asked for it or but pr is unavailable. Still prefer but pr new when you are already working from GitButler branch IDs.
For stacked branches, but pr is mandatory. Create and manage stacked PRs with GitButler so PR bases match the stack and GitButler can maintain the stack metadata in PR description footers. Do not create stacked PRs with gh pr create or other forge tools.
To publish a whole stack, create the PR from the top branch you want published:
but pr new <top-branch-id> -t
That creates or updates reviews for that branch and its dependencies in stack order. Use but pr auto-merge <selector>, but pr set-draft <selector>, and but pr set-ready <selector> for follow-up PR management; selectors can be branch names, branch IDs, stack IDs, or numeric review IDs.
Stacked dependency / commit-lock recovery
A dependency lock occurs when a file was originally committed on branch A, but you're trying to commit changes to it on branch B. Symptoms:
but commit succeeds but the file still appears in uncommittedChanges in the returned status
- The file still shows as "uncommitted" in the status output
Recovery: Stack your branch on the dependency branch, then commit:
but status -fv — identify which branch originally owns the file (check commit history).
but move <your-branch-name> <dependency-branch-name> — stack your branch on the dependency. Uses full branch names, not CLI IDs.
but status -fv — the file should now be committable. Commit it.
but commit <branch> -m "<msg>" --changes <id>
If but move <branch> <target-branch> fails: Do NOT try uncommit, squash, or undo to work around it — these will leave the workspace in a worse state. Instead, re-run but status -fv to confirm both branches still exist and are applied, then retry with exact branch names from the status output.
Resolve conflicts after reorder/move
NEVER use git add, git commit, git checkout --theirs, git checkout --ours, or any git write commands during resolution. Only use but resolve commands and edit files directly with the Edit tool.
If but move causes conflicts (conflicted commits in status):
but status -fv — find commits marked as conflicted.
but resolve <commit-id> — enter resolution mode. This puts conflict markers in the files.
- Read the conflicted files to see the
<<<<<<< / ======= / >>>>>>> markers.
- Edit the files to resolve conflicts by choosing the correct content and removing markers.
but resolve finish — finalize. Do NOT run this without editing the files first.
- Repeat for any remaining conflicted commits.
Common mistakes: Do NOT use but amend on conflicted commits (it won't work). Do NOT skip step 4 — you must actually edit the files to remove conflict markers before finishing.
Conflicts in uncommitted files
but status lists uncommitted files with unresolved merge conflicts marked
{conflicted}; they are excluded from committable changes. These conflicts are
outside but resolve mode. Choose the desired contents or delete the file, then
run git add -- <path> to mark it resolved. This is the one case where using
git add is permitted.
Git-to-But Map
| git | but |
|---|
git status | but status for branch/stack/commit overview; but status -fv for file/hunk details; but diff for selected dirty changes |
git add + git commit | but commit ... --changes ... |
git checkout -b + commit | but commit <branch> -c -m ... --changes ... |
Notes
- Use plain
but status for commit order, branch/stack placement, and conflict overview. Escalate to but status -fv only when file/hunk IDs or per-commit file details are needed.
- Read-only git inspection (
git log, git blame, git show --stat) is allowed.
- After a successful mutation, trust the workspace state it printed. Re-run
but status or but status -fv only if that output lacks the ID you need or files changed since.
- Avoid
--help probes; use this skill and references/reference.md first. Only use --help after a command fails or required syntax is missing from the installed references.