Skip to content

Commit a2bd921

Browse files
committed
Add graphite skill
1 parent 664a87a commit a2bd921

10 files changed

Lines changed: 3360 additions & 0 deletions

File tree

Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
---
2+
name: graphite
3+
description: This skill will be used when the user asks about "graphite", "gt commands", "stacked PRs", "stacking pull requests", "merge queue", "gt sync", "gt submit", "gt create", "gt modify", or needs help with Graphite CLI workflows, PR stacking, or Graphite integrations.
4+
---
5+
6+
# Graphite
7+
8+
## Overview
9+
10+
Graphite is a platform for creating, reviewing, and merging stacked pull requests with GitHub. The `gt` CLI simplifies git commands and enables PR stacking to help developers move faster and stay unblocked by breaking large changes into small, incremental, reviewable pieces.
11+
12+
## Core Concepts
13+
14+
### What is Stacking?
15+
16+
Stacking organizes related code changes as a sequence of dependent pull requests rather than one large PR. Benefits:
17+
- Stay unblocked while waiting for reviews
18+
- Smaller PRs get reviewed faster
19+
- Clearer review context for each change
20+
- Merge independently as reviews complete
21+
22+
### Stack Structure
23+
24+
```
25+
main
26+
└── feature-api (PR #1) ← bottom of stack
27+
└── feature-frontend (PR #2)
28+
└── feature-tests (PR #3) ← top of stack
29+
```
30+
31+
## Quick Start
32+
33+
### Installation
34+
35+
```bash
36+
# macOS
37+
brew install withgraphite/tap/graphite
38+
39+
# npm
40+
npm install -g @withgraphite/graphite-cli
41+
42+
# Authenticate
43+
gt auth --token <github-token>
44+
```
45+
46+
### Basic Workflow
47+
48+
```bash
49+
# 1. Create first branch in stack
50+
gt checkout main
51+
# make changes...
52+
gt create --all --message "feat(api): add user endpoint"
53+
54+
# 2. Stack another PR on top
55+
# make more changes...
56+
gt create --all --message "feat(frontend): add user page"
57+
58+
# 3. Submit entire stack
59+
gt submit --stack # or: gt ss
60+
61+
# 4. Sync with trunk and cleanup
62+
gt sync
63+
```
64+
65+
## Essential Commands
66+
67+
### Navigation
68+
69+
| Command | Alias | Description |
70+
|---------|-------|-------------|
71+
| `gt checkout` | `gt co` | Switch to branch (interactive picker) |
72+
| `gt up` | `gt u` | Move up one branch in stack |
73+
| `gt down` | `gt d` | Move down one branch in stack |
74+
| `gt top` | `gt t` | Jump to top of stack |
75+
| `gt bottom` | `gt b` | Jump to bottom of stack |
76+
| `gt log` | - | Display full stack with PR info |
77+
| `gt log short` | `gt ls` | List all branches in stack |
78+
79+
### Creating & Modifying
80+
81+
| Command | Alias | Description |
82+
|---------|-------|-------------|
83+
| `gt create -am "msg"` | `gt c -am` | Create branch, stage all, commit |
84+
| `gt modify -a` | `gt m -a` | Stage all and amend current commit |
85+
| `gt modify -c` | `gt m -c` | Add new commit (don't amend) |
86+
| `gt modify -cam "msg"` | - | Stage all, add commit with message |
87+
88+
### Syncing & Submitting
89+
90+
| Command | Alias | Description |
91+
|---------|-------|-------------|
92+
| `gt sync` | - | Pull trunk, restack, cleanup merged |
93+
| `gt submit` | - | Push current + downstack, create PRs |
94+
| `gt submit --stack` | `gt ss` | Push entire stack |
95+
| `gt submit -u` | - | Update existing PRs only |
96+
97+
### Reorganizing
98+
99+
| Command | Alias | Description |
100+
|---------|-------|-------------|
101+
| `gt restack` | - | Rebase stack on updated parents |
102+
| `gt move` | - | Change branch parent |
103+
| `gt fold` | - | Merge branch into parent |
104+
| `gt split` | `gt sp` | Split branch by commit/hunk/file |
105+
| `gt squash` | `gt sq` | Combine commits |
106+
| `gt reorder` | - | Rearrange branches in stack |
107+
| `gt absorb` | `gt ab` | Distribute staged changes to relevant commits |
108+
109+
### Collaboration & Recovery
110+
111+
| Command | Description |
112+
|---------|-------------|
113+
| `gt get <branch>` | Fetch teammate's stack locally |
114+
| `gt track` | Start managing existing git branch |
115+
| `gt untrack` | Stop tracking branch |
116+
| `gt freeze` | Lock branch against modifications |
117+
| `gt undo` | Reverse last Graphite operation |
118+
119+
## Common Workflows
120+
121+
### Addressing Review Feedback
122+
123+
```bash
124+
# 1. Checkout the PR needing changes
125+
gt checkout first_pr_in_stack
126+
127+
# 2. Make edits, then amend
128+
gt modify -a
129+
130+
# 3. Resubmit (auto-restacks dependent branches)
131+
gt submit --stack
132+
```
133+
134+
### Adding Changes to Middle of Stack
135+
136+
```bash
137+
# Stage specific changes
138+
git add specific_file.js
139+
140+
# Absorb distributes to relevant commits downstack
141+
gt absorb
142+
```
143+
144+
### Splitting a Large Branch
145+
146+
```bash
147+
# Interactive split by commit, hunk, or file
148+
gt split
149+
```
150+
151+
### Merging Stack
152+
153+
Navigate to Graphite web UI to merge, or use `gt merge` for the topmost PR. The merge queue handles dependent PRs automatically.
154+
155+
## Web Features
156+
157+
### PR Inbox
158+
159+
An "email client" for PRs with sections:
160+
- Needs your review
161+
- Approved / Returned to you
162+
- Merging / Recently merged
163+
- Drafts / Waiting for review
164+
165+
Customize with filters, search (Cmd+K), and shareable filter links.
166+
167+
### AI Reviews
168+
169+
Automatic code analysis identifying:
170+
- Logic bugs and edge cases
171+
- Security vulnerabilities
172+
- Performance issues
173+
- Debug statements / accidentally committed code
174+
175+
Configure in repository settings. Focuses on real bugs, not style nitpicks.
176+
177+
### Automations
178+
179+
Create rules that trigger when PRs match criteria:
180+
- Add reviewers (individuals or teams)
181+
- Apply labels
182+
- Post comments
183+
- Send Slack notifications
184+
185+
Configure via Graphite web app → Automations.
186+
187+
## Merge Queue
188+
189+
Stack-aware merge queue that:
190+
- Validates stacked PRs in parallel (not sequentially)
191+
- Enables fast-forward merges without re-running CI
192+
- Keeps trunk stable with automatic rebasing
193+
194+
Strategies: **Rebase** (preserve commits), **Squash** (one commit per PR), or **Fast-Forward**.
195+
196+
Setup: Configure GitHub branch protection, then enable in Graphite repository settings.
197+
198+
## GT MCP Integration
199+
200+
Enable AI agents to create stacked PRs automatically:
201+
202+
```bash
203+
# Claude Code
204+
claude mcp add graphite gt mcp
205+
206+
# Cursor (add to settings)
207+
{
208+
"mcpServers": {
209+
"graphite": { "command": "gt", "args": ["mcp"] }
210+
}
211+
}
212+
```
213+
214+
Requires CLI version 1.6.7+.
215+
216+
## CI Optimizations
217+
218+
Reduce CI runs for stacked PRs by configuring Graphite's CI optimizer:
219+
- Configure which PRs in stack run CI (top, bottom, all)
220+
- API endpoint returns boolean for skip decision
221+
- Fail-safe: if API errors, CI runs normally
222+
223+
See `references/integrations.md` for GitHub Actions and Buildkite setup.
224+
225+
## Configuration
226+
227+
### Shell Completion
228+
229+
```bash
230+
gt completion >> ~/.zshrc # zsh
231+
gt completion >> ~/.bashrc # bash
232+
gt fish >> ~/.config/fish/completions/gt.fish
233+
```
234+
235+
### Branch Naming
236+
237+
Configure via `gt config`:
238+
- Custom prefix (e.g., initials)
239+
- Date prepending
240+
- Character restrictions
241+
242+
### Multiple GitHub Accounts
243+
244+
Define profiles in `~/.config/graphite/user_config` for separate auth tokens.
245+
246+
## Monorepo Optimizations
247+
248+
In large monorepos with thousands of branches, `gt` commands can be slow. The main bottlenecks are:
249+
250+
1. **Branch enumeration** - `git for-each-ref` lists all branches
251+
2. **Metadata reading** - Spawns one git process per tracked branch
252+
3. **Git fetch** - Negotiates with thousands of remote refs
253+
254+
### Cleanup Stale Branches
255+
256+
Untrack all branches with CLOSED or MERGED PRs (requires `gh` CLI):
257+
258+
```bash
259+
bash ~/.claude/skills/graphite/scripts/cleanup-stale-branches.sh
260+
```
261+
262+
See `scripts/cleanup-stale-branches.sh` for the full script.
263+
264+
### Other Optimizations
265+
266+
- **Use `gt restack` instead of `gt sync`** when you don't need to fetch from remote
267+
- **Use direct checkout** (`gt checkout branch-name`) instead of interactive picker
268+
- **Limit git fetch refspec** to only fetch branches you need:
269+
```bash
270+
git config remote.origin.fetch '+refs/heads/main:refs/remotes/origin/main'
271+
git config --add remote.origin.fetch '+refs/heads/your-prefix/*:refs/remotes/origin/your-prefix/*'
272+
```
273+
- **Enable git maintenance** for faster git operations:
274+
```bash
275+
git maintenance start
276+
git commit-graph write --reachable
277+
```
278+
279+
## Troubleshooting Quick Reference
280+
281+
| Issue | Solution |
282+
|-------|----------|
283+
| Stack out of sync | `gt sync` to pull trunk and restack |
284+
| Merge conflicts | Resolve conflicts, then `gt continue` |
285+
| Wrong parent branch | `gt move` to reassign parent |
286+
| Need to undo | `gt undo` reverses last operation |
287+
| Branch not tracked | `gt track` to add existing branch |
288+
| Slow gt commands | Run cleanup script above, use `gt restack` instead of `gt sync` |
289+
290+
## Background Agents
291+
292+
Describe tasks in plain language; Graphite spins up sandboxes to write code, run tests, and open PRs:
293+
- Quick fixes from phone/browser without cloning
294+
- Generate boilerplate and scaffolding
295+
- Add tests without context-switching
296+
- $10 free credits; unlimited with own Claude API key
297+
298+
## Graphite Chat
299+
300+
AI assistant in PR review interface:
301+
- Request PR summaries and explanations
302+
- Propose fixes applied with one click
303+
- Search codebase for related code
304+
- Debug CI failures with full context
305+
306+
## Additional Resources
307+
308+
### Reference Files
309+
310+
For detailed documentation, consult:
311+
312+
**CLI & Commands:**
313+
- **`references/commands.md`** - Complete command reference with all options, Git vs gt comparison, installation, authentication
314+
315+
**Workflows:**
316+
- **`references/stacking-workflows.md`** - Detailed stacking patterns, advanced workflows, collaboration, common scenarios
317+
- **`references/best-practices.md`** - Reviewing stacked PRs, creating stacks, organization setup, anti-patterns
318+
319+
**Platform Features:**
320+
- **`references/merge-queue.md`** - Merge queue setup, optimizations (parallel CI, batching, fast-forward), troubleshooting
321+
- **`references/ai-features.md`** - AI reviews, Graphite Chat, Background Agents, GT MCP integration, customization
322+
- **`references/web-features.md`** - PR inbox, insights, admin, automations, merging, plans & billing
323+
324+
**Configuration:**
325+
- **`references/integrations.md`** - Slack, VS Code, Linear, Jira, CI optimizations setup
326+
- **`references/configuration.md`** - Full CLI configuration options, branch naming, multi-account
327+
328+
### External Links
329+
330+
- Documentation: https://graphite.com/docs
331+
- LLM-optimized docs: https://graphite.com/docs/llms-full.txt
332+
- Activate CLI: https://app.graphite.com/activate

0 commit comments

Comments
 (0)