graphite
Original:🇺🇸 English
Translated
Work with Graphite (gt) for stacked PRs - creating, navigating, and managing PR stacks.
3installs
Added on
NPX Install
npx skill4agent add withgraphite/agent-skills graphiteTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Graphite Skill
Work with Graphite () for creating, navigating, and managing stacked pull requests.
gtQuick Reference
| I want to... | Command |
|---|---|
| Create a new branch/PR | |
| Amend current branch | |
| Navigate up the stack | |
| Navigate down the stack | |
| Jump to top of stack | |
| Jump to bottom of stack | |
| View stack structure | |
| Submit stack for review | |
| Rebase stack on trunk | |
| Change branch parent | |
| Rename current branch | |
| Move branch in stack | |
What Makes a Good PR?
In roughly descending order of importance:
- Atomic/hermetic - independent of other changes; will pass CI and be safe to deploy on its own
- Narrow semantic scope - changes only to module X, or the same change across modules X, Y, Z
- Small diff - (heuristic) small total diff line count
Do NOT worry about creating TOO MANY pull requests. It is always preferable to create more pull requests than fewer.
NO CHANGE IS TOO SMALL: tiny PRs allow for the medium/larger-sized PRs to have more clarity.
Always argue in favor of creating more PRs, as long as they independently pass build.
Branch Naming Conventions
When naming PRs in a stack, follow this syntax:
terse-stack-feature-name/terse-description-of-changeFor example, a 4 PR stack:
auth-bugfix/reorder-args
auth-bugfix/improve-logging
auth-bugfix/improve-documentation
auth-bugfix/handle-401-status-codesCreating a Stack
Basic Workflow
- Make changes to files
- Stage changes:
git add <files> - Create branch:
gt create branch-name -m "commit message" - Repeat for each PR in the stack
- Submit:
gt submit --no-interactive
Handle Untracked Branches (common with worktrees)
Before creating branches, check if the current branch is tracked:
bash
gt branch infoIf you see "ERROR: Cannot perform this operation on untracked branch":
Option A (Recommended): Track temporarily, then re-parent
- Track current branch:
gt track -p main - Create your stack normally with
gt create - After creating ALL branches, re-parent your first new branch onto main:
bash
gt checkout <first-branch-of-your-stack> gt track -p main gt restack
Option B: Stash changes and start from main
git stashgit checkout main && git pull- Create new branch and unstash:
git checkout -b temp-working && git stash pop - Proceed with and
gt track -p maingt create
Navigating a Stack
bash
# Move up one branch (toward top of stack)
gt up
# Move down one branch (toward trunk)
gt down
# Jump to top of stack
gt top
# Jump to bottom of stack (first branch above trunk)
gt bottom
# View the full stack structure
gt lsModifying a Stack
Amend Current Branch
bash
git add <files>
gt modify -m "updated commit message"Reorder Branches
Use to reorder branches in the stack. This is simpler than trying to use .
gt movegt create --insertRe-parent a Stack
If you created a stack on top of a feature branch but want it based on main:
bash
# Go to first branch of your stack
gt checkout <first-branch>
# Change its parent to main
gt track --parent main
# Rebase the entire stack
gt restackRename a Branch
bash
gt rename new-branch-nameResetting Commits to Unstaged Changes
If changes are already committed but you want to re-stack them differently:
bash
# Reset the last commit, keeping changes unstaged
git reset HEAD^
# Reset multiple commits (e.g., last 2 commits)
git reset HEAD~2
# View the diff to understand what you're working with
git diff HEADBefore Submitting
Verify Stack is Rooted on Main
Before running , verify the first PR is parented on :
gt submitmainbash
gt lsIf the first branch has a parent other than :
mainbash
gt checkout <first-branch>
gt track -p main
gt restackRun Validation
After creating each PR, run appropriate linting, building, and testing:
- Refer to the project's CLAUDE.md for specific commands
- If validation fails, fix the issue, stage changes, and use
gt modify
Submitting and Updating PRs
Submit the Stack
bash
gt submit --no-interactiveUpdate PR Descriptions
After submitting, use to set proper titles and descriptions.
gh pr editIMPORTANT: Never use Bash heredocs for PR descriptions - shell escaping breaks markdown tables, code blocks, etc. Instead:
- Use the tool to create
Writewith the full markdown content/tmp/pr-body.md - Use with
gh pr edit:--body-file
bash
gh pr edit <PR_NUMBER> --title "stack-name: description" --body-file /tmp/pr-body.mdPR descriptions must include:
- Stack Context: What is the bigger goal of this stack?
- What? (optional for small changes): Super terse, focus on what not why
- Why?: What prompted the change? Why this solution? How does it fit into the stack?
Example (for a PR in a 3-PR stack adding a warning feature):
markdown
## Stack Context
This stack adds a warning on the merge button when users are bypassing GitHub rulesets.
## Why?
Users who can bypass rulesets (via org admin or team membership) currently see no indication
they're circumventing branch protection. This PR threads the bypass data from the server to
enable the frontend warning (PR 2) to display it.Troubleshooting
| Problem | Solution |
|---|---|
| "Cannot perform this operation on untracked branch" | Run |
| Stack parented on wrong branch | Use |
| Need to reorder PRs | Use |
| Conflicts during restack | Resolve conflicts, then |
| Want to split a PR | Reset commits ( |
| Need to delete a branch (non-interactive) | |
| Use targeted |
| Rebase interrupted mid-conflict | Check if files are resolved but unstaged, then |
Advanced: Surgical Rebasing in Complex Stacks
In deeply nested stacks with many sibling branches, can be problematic:
gt restack- It restacks ALL branches that need it, not just your stack
- Can hit conflicts in completely unrelated branches
- Is all-or-nothing - hard to be surgical
When to Use git rebase
Instead of gt restack
git rebasegt restackUse direct when:
git rebase- You only want to update specific branches in your stack
- is hitting conflicts in unrelated branches
gt restack - You need to skip obsolete commits during the rebase
Targeted Rebase Workflow
bash
# 1. Checkout the branch you want to rebase
git checkout my-feature-branch
# 2. Rebase onto the target (e.g., updated parent branch)
git rebase target-branch
# 3. If you hit conflicts:
# - Resolve the conflict in the file
# - Stage it: git add <file>
# - Continue: git rebase --continue
# 4. If a commit is obsolete and should be skipped:
git rebase --skip
# 5. After rebase, use gt modify to sync graphite's tracking
gt modify --no-editRecovering from Interrupted Rebase (Context Reset)
If a rebase was interrupted (e.g., Claude session ran out of context):
-
Check status:bash
git status # Look for "interactive rebase in progress" and "Unmerged paths" -
Read the "unmerged" files - they may already be resolved (no conflict markers)
-
If already resolved, just stage and continue:bash
git add <resolved-files> git rebase --continue -
If still has conflict markers, resolve them first, then stage and continue
Deleting Branches from a Stack
bash
# Delete a branch (non-interactive, even if not merged)
gt delete branch-to-delete -f -q
# Also delete all children (upstack)
gt delete branch-to-delete -f -q --upstack
# Also delete all ancestors (downstack)
gt delete branch-to-delete -f -q --downstackFlags:
- /
-f: Delete even if not merged or closed--force - /
-q: Implies--quiet, minimizes output--no-interactive
After deleting intermediate branches, children are automatically restacked onto the parent. If you need to manually update tracking:
bash
gt checkout child-branch
gt track --parent new-parent-branch