git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/gt" ~/.claude/skills/majiayu000-claude-skill-registry-gt && rm -rf "$T"
skills/data/gt/SKILL.mdGraphite
Overview
Graphite (gt) is a CLI tool for managing stacked pull requests - breaking large features into small, incremental changes built on top of each other. This skill provides the mental model, command reference, and workflow patterns needed to work effectively with gt.
Core Mental Model
Stacks are Linear Chains
A stack is a sequence of branches where each branch (except trunk) has exactly one parent:
VALID STACK (linear): main → feature-a → feature-b → feature-c INVALID (not a stack): main → feature-a → feature-b └─────→ feature-x
Key Concepts
- Parent-Child Relationships: Every branch tracked by gt (except trunk) has exactly one parent branch it builds upon
- Auto-restacking: When modifying a branch, gt automatically rebases all upstack branches to include changes
- Directional Navigation:
- Downstack/Down: Toward trunk (toward the base) -
moves from feature-b → feature-a → maingt down - Upstack/Up: Away from trunk (toward the tip) -
moves from feature-a → feature-b → feature-cgt up
- Downstack/Down: Toward trunk (toward the base) -
- Trunk: The main branch (usually
ormain
) that all stacks build uponmaster
Stack Visualization - CRITICAL MENTAL MODEL
When working with Graphite stacks, always visualize trunk at the BOTTOM:
TOP ↑ feat-3 ← upstack (leaf) feat-2 feat-1 BOTTOM ↓ main ← downstack (trunk)
Directional Terminology - MUST UNDERSTAND
- UPSTACK / UP = away from trunk = toward TOP = toward leaves
- DOWNSTACK / DOWN = toward trunk = toward BOTTOM = toward main
Detailed Examples
Given stack:
main → feat-1 → feat-2 → feat-3
If current branch is
:feat-1
- Upstack:
,feat-2
(children, toward top)feat-3 - Downstack:
(parent, toward bottom)main
If current branch is
(at top):feat-3
- Upstack: (nothing, already at top/leaf)
- Downstack:
,feat-2
,feat-1
(ancestors, toward bottom)main
Why This Mental Model Is Critical
🔴 Commands depend on this visualization:
/gt up
navigate the stackgt down
traverses branches in specific directionland-stack- Stack traversal logic (parent/child relationships)
🔴 Common mistake: Thinking "upstack" means "toward trunk"
- WRONG: upstack = toward main ❌
- CORRECT: upstack = away from main ✅
🔴 PR landing order: Always bottom→top (main first, then each layer up)
Metadata Storage
All gt metadata is stored in the shared
.git directory (accessible across worktrees):
- Repository-level configuration (trunk branch).git/.graphite_repo_config
- Branch relationships (parent-child graph).git/.graphite_cache_persist
- Cached GitHub PR information.git/.graphite_pr_info
Important: Metadata is shared across all worktrees since it's in the common
.git directory.
Essential Commands
Common Workflow Commands
| Command | Alias | Purpose |
|---|---|---|
| | Create new branch stacked on current branch and commit staged changes |
| | Modify current branch (amend commit) and auto-restack children |
| | Push branches and create/update PRs |
| | Submit entire stack (up + down) |
| - | Sync from remote and prompt to delete merged branches |
Navigation Commands
| Command | Alias | Purpose |
|---|---|---|
| | Move up stack (away from trunk) |
| | Move down stack (toward trunk) |
| | Move to tip of stack |
| | Move to bottom of stack |
| | Interactive branch checkout |
Stack Management
| Command | Purpose |
|---|---|
| Ensure each branch has its parent in git history |
| Rebase current branch onto different parent |
| Fold branch's changes into parent |
| Split current branch into multiple single-commit branches |
| Visualize stack structure |
Branch Info & Management
| Command | Purpose |
|---|---|
| Show branch info (parent, children, commit SHA) |
| Show parent branch name |
| Show children branch names |
| Start tracking branch with gt (set parent) |
| Stop tracking branch with gt |
| Delete branch and update metadata |
| Rename branch and update metadata |
Workflow Patterns
Pattern 1: Creating a New Stack
Build a feature in multiple reviewable chunks:
# 1. Start from trunk gt checkout main git pull # 2. Create first branch gt create phase-1 -m "Add API endpoints" # ... make changes ... git add . gt modify -m "Add API endpoints" # 3. Create second branch on top gt create phase-2 -m "Update frontend" # ... make changes ... git add . gt modify -m "Update frontend" # 4. Submit entire stack gt submit --stack # Result: 2 PRs created # PR #101: phase-1 (base: main) # PR #102: phase-2 (base: phase-1)
Pattern 2: Responding to Review Feedback
Update a branch in the middle of a stack:
# Navigate down to target branch gt down # Repeat as needed # Make changes # ... edit files ... git add . # Modify (auto-restacks upstack branches) gt modify -m "Address review feedback" # Resubmit stack gt submit --stack
Pattern 3: Adding to Existing Stack
Insert a new branch in the middle:
# Checkout the parent where you want to insert gt checkout phase-1 # Create new branch with --insert gt create phase-1.5 --insert -m "Add validation" # Select which child to move onto new branch # Interactive prompt appears # Submit new PR gt submit
Pattern 4: Syncing After Merges
Clean up after PRs merge on GitHub:
# Run sync gt sync # Prompts to delete merged branches # Confirms deletion y # Result: # - Merged branches deleted locally # - Remaining branches rebased onto trunk # - PR bases updated on GitHub
Pattern 5: Splitting Large Changes
Break up a large commit into reviewable pieces:
# Checkout branch with large commit gt checkout large-feature # Split into single-commit branches gt split # Rename branches meaningfully gt rename add-api-endpoints gt up gt rename add-frontend gt up gt rename add-tests # Submit gt submit --stack
Common Mistakes to Avoid
-
Don't use
directly: Usegit rebase
orgt modify
- gt needs to update metadata during rebasinggt restack -
Don't delete branches with
: Usegit branch -d
- metadata needs to be updated to re-parent childrengt delete -
Don't assume
only affects current branch: It submits downstack too (all ancestors). Usegt submit
to include upstackgt submit --stack -
Don't forget to
after merges: Stale branches accumulate and metadata gets outdatedgt sync -
⚠️ NEVER use
for branch status: The output format is counterintuitive and confuses agents. Usegt log short
,gt branch info
, orgt parent
for explicit metadata access insteadgt children
Quick Decision Tree
When to use gt commands:
- Start new work →
(sets parent relationship)gt create - Edit current branch →
(auto-restacks children)gt modify - Navigate stack →
(move through chain)gt up/down/top/bottom - View structure →
(see visualization)gt log - Get parent branch →
(parse "Parent:" line)gt branch info - Get branch relationships →
/gt parent
(quick access)gt children - Submit PRs →
(create/update all PRs)gt submit --stack - After merges →
(clean up + rebase)gt sync - Reorganize →
(change parent)gt move - Combine work →
(merge into parent)gt fold - Split work →
(break into branches)gt split
Resources
references/
Contains detailed command reference and comprehensive mental model documentation:
- Complete command reference, metadata format details, and advanced patternsgt-reference.md
Load this reference when users need detailed information about specific gt commands, metadata structure, or complex workflow scenarios.