| name | graphite |
| description | Graphite CLI (gt) patterns for managing stacked pull requests. Use whenever the user mentions graphite, the `gt` command, PR stacks, or stacked diffs. Also triggers when starting development work in a repository where graphite is initialized (`.git/refs/graphite` exists or `gt` commands have been used). Invoke proactively when the user is creating branches, submitting PRs, or navigating between related branches in a collaborative repo — even if they don't mention graphite by name. |
Graphite CLI for Stacked PRs
Graphite (gt) is a CLI for managing stacked pull requests — chains of dependent branches where each PR builds on the previous one. It automates the rebasing, syncing, and PR creation that vanilla Git makes painful.
Detecting Graphite in a Repo
Graphite is initialized if .git/refs/graphite exists or if gt log succeeds. If unsure, run gt log — it either shows the stack or errors clearly.
Core Mental Model
Graphite tracks a stack: an ordered chain of branches, each branching off the one below it. Trunk (usually main) is the base. When a branch lower in the stack changes, Graphite can automatically rebase everything above it (restack).
Key terms:
- Trunk: the base branch (main/master)
- Stack: the ordered chain of branches above trunk
- Upstack: branches above the current one
- Downstack: branches below the current one (toward trunk)
Essential Commands
Starting Work
gt sync
gt create -am "description"
gt create
Navigating the Stack
gt log
gt up
gt down
gt top
gt bottom
gt checkout <branch>
Making Changes
gt modify
gt modify --all
gt modify --commit
gt modify --message "msg"
Submitting PRs
gt submit
gt submit --stack
gt submit --stack --draft
gt submit --stack --update-only
gt submit --no-edit
Keeping Up to Date
gt restack
Restructuring the Stack
gt move
gt fold
gt pop
gt squash
Recovery
gt undo
gt abort
Collaboration
gt get <branch>
gt track
gt freeze
gt unfreeze
Common Workflows
Starting a new feature in a stack
gt sync
gt create -m "add auth layer"
gt create -m "add user model"
gt ss
Amending after PR feedback
gt co <branch>
gt m -a
gt ss -u
After trunk advances (teammates merged something)
gt sync
Editing a mid-stack branch
gt co <mid-stack-branch>
gt m -a
gt restack
gt ss -u
Resolving a restack conflict
When gt restack hits a conflict:
- Resolve the conflict in the affected files
git add <files>
gt restack --continue — resumes the restack
- Or
gt abort to cancel and return to the pre-restack state
Diagnosing Common Errors
"Branch is not tracked by Graphite": Run gt track to register the branch, or gt create to make a new tracked branch from the current one.
"Restack failed with conflicts": Resolve conflicts manually, git add the resolved files, then gt restack --continue. Use gt abort to bail out entirely.
"Stack is out of date": Run gt sync to pull trunk and restack, then retry the failing command.
"PR already exists": gt submit will update it rather than create a new one. Use --update-only to be explicit.
Full Documentation
If a question arises that this skill doesn't cover, fetch the full Graphite docs for LLMs:
https://graphite.com/docs/llms-full.txt
When NOT to Use Graphite
- Personal/solo repos where PRs aren't part of the workflow — use plain Git
- Single-commit changes that don't benefit from stacking —
gt submit alone is fine, no need for a full stack