$npx -y skills add withgraphite/agent-skills --skill graphiteWork with Graphite (gt) for stacked PRs - creating, navigating, and managing PR stacks.
| 1 | # Graphite Skill |
| 2 | |
| 3 | Work with Graphite (`gt`) for creating, navigating, and managing stacked pull requests. |
| 4 | |
| 5 | ## Quick Reference |
| 6 | |
| 7 | | I want to... | Command | |
| 8 | |--------------|---------| |
| 9 | | Create a new branch/PR | `gt create branch-name -m "message"` | |
| 10 | | Amend current branch | `gt modify -m "message"` | |
| 11 | | Navigate up the stack | `gt up` | |
| 12 | | Navigate down the stack | `gt down` | |
| 13 | | Jump to top of stack | `gt top` | |
| 14 | | Jump to bottom of stack | `gt bottom` | |
| 15 | | View stack structure | `gt ls` | |
| 16 | | Submit stack for review | `gt submit --no-interactive` | |
| 17 | | Rebase stack on trunk | `gt restack` | |
| 18 | | Change branch parent | `gt track --parent <branch>` | |
| 19 | | Rename current branch | `gt rename <new-name>` | |
| 20 | | Move branch in stack | `gt move` | |
| 21 | |
| 22 | --- |
| 23 | |
| 24 | ## What Makes a Good PR? |
| 25 | |
| 26 | In roughly descending order of importance: |
| 27 | |
| 28 | - **Atomic/hermetic** - independent of other changes; will pass CI and be safe to deploy on its own |
| 29 | - **Narrow semantic scope** - changes only to module X, or the same change across modules X, Y, Z |
| 30 | - **Small diff** - (heuristic) small total diff line count |
| 31 | |
| 32 | **Do NOT worry about creating TOO MANY pull requests.** It is **always** preferable to create more pull requests than fewer. |
| 33 | |
| 34 | **NO CHANGE IS TOO SMALL:** tiny PRs allow for the medium/larger-sized PRs to have more clarity. |
| 35 | |
| 36 | Always argue in favor of creating more PRs, as long as they independently pass build. |
| 37 | |
| 38 | --- |
| 39 | |
| 40 | ## Branch Naming Conventions |
| 41 | |
| 42 | When naming PRs in a stack, follow this syntax: |
| 43 | |
| 44 | `terse-stack-feature-name/terse-description-of-change` |
| 45 | |
| 46 | For example, a 4 PR stack: |
| 47 | |
| 48 | ``` |
| 49 | auth-bugfix/reorder-args |
| 50 | auth-bugfix/improve-logging |
| 51 | auth-bugfix/improve-documentation |
| 52 | auth-bugfix/handle-401-status-codes |
| 53 | ``` |
| 54 | |
| 55 | --- |
| 56 | |
| 57 | ## Creating a Stack |
| 58 | |
| 59 | ### Basic Workflow |
| 60 | |
| 61 | 1. Make changes to files |
| 62 | 2. Stage changes: `git add <files>` |
| 63 | 3. Create branch: `gt create branch-name -m "commit message"` |
| 64 | 4. Repeat for each PR in the stack |
| 65 | 5. Submit: `gt submit --no-interactive` |
| 66 | |
| 67 | ### Handle Untracked Branches (common with worktrees) |
| 68 | |
| 69 | Before creating branches, check if the current branch is tracked: |
| 70 | |
| 71 | ```bash |
| 72 | gt branch info |
| 73 | ``` |
| 74 | |
| 75 | If you see "ERROR: Cannot perform this operation on untracked branch": |
| 76 | |
| 77 | **Option A (Recommended): Track temporarily, then re-parent** |
| 78 | 1. Track current branch: `gt track -p main` |
| 79 | 2. Create your stack normally with `gt create` |
| 80 | 3. After creating ALL branches, re-parent your first new branch onto main: |
| 81 | ```bash |
| 82 | gt checkout <first-branch-of-your-stack> |
| 83 | gt track -p main |
| 84 | gt restack |
| 85 | ``` |
| 86 | |
| 87 | **Option B: Stash changes and start from main** |
| 88 | 1. `git stash` |
| 89 | 2. `git checkout main && git pull` |
| 90 | 3. Create new branch and unstash: `git checkout -b temp-working && git stash pop` |
| 91 | 4. Proceed with `gt track -p main` and `gt create` |
| 92 | |
| 93 | --- |
| 94 | |
| 95 | ## Navigating a Stack |
| 96 | |
| 97 | ```bash |
| 98 | # Move up one branch (toward top of stack) |
| 99 | gt up |
| 100 | |
| 101 | # Move down one branch (toward trunk) |
| 102 | gt down |
| 103 | |
| 104 | # Jump to top of stack |
| 105 | gt top |
| 106 | |
| 107 | # Jump to bottom of stack (first branch above trunk) |
| 108 | gt bottom |
| 109 | |
| 110 | # View the full stack structure |
| 111 | gt ls |
| 112 | ``` |
| 113 | |
| 114 | --- |
| 115 | |
| 116 | ## Modifying a Stack |
| 117 | |
| 118 | ### Amend Current Branch |
| 119 | |
| 120 | ```bash |
| 121 | git add <files> |
| 122 | gt modify -m "updated commit message" |
| 123 | ``` |
| 124 | |
| 125 | ### Reorder Branches |
| 126 | |
| 127 | Use `gt move` to reorder branches in the stack. This is simpler than trying to use `gt create --insert`. |
| 128 | |
| 129 | ### Re-parent a Stack |
| 130 | |
| 131 | If you created a stack on top of a feature branch but want it based on main: |
| 132 | |
| 133 | ```bash |
| 134 | # Go to first branch of your stack |
| 135 | gt checkout <first-branch> |
| 136 | |
| 137 | # Change its parent to main |
| 138 | gt track --parent main |
| 139 | |
| 140 | # Rebase the entire stack |
| 141 | gt restack |
| 142 | ``` |
| 143 | |
| 144 | ### Rename a Branch |
| 145 | |
| 146 | ```bash |
| 147 | gt rename new-branch-name |
| 148 | ``` |
| 149 | |
| 150 | --- |
| 151 | |
| 152 | ## Resetting Commits to Unstaged Changes |
| 153 | |
| 154 | If changes are already committed but you want to re-stack them differently: |
| 155 | |
| 156 | ```bash |
| 157 | # Reset the last commit, keeping changes unstaged |
| 158 | git reset HEAD^ |
| 159 | |
| 160 | # Reset multiple commits (e.g., last 2 commits) |
| 161 | git reset HEAD~2 |
| 162 | |
| 163 | # View the diff to understand what you're working with |
| 164 | git diff HEAD |
| 165 | ``` |
| 166 | |
| 167 | --- |
| 168 | |
| 169 | ## Before Submitting |
| 170 | |
| 171 | ### Verify Stack is Rooted on Main |
| 172 | |
| 173 | Before running `gt submit`, verify the first PR is parented on `main`: |
| 174 | |
| 175 | ```bash |
| 176 | gt ls |
| 177 | ``` |
| 178 | |
| 179 | If the first branch has a parent other than `main`: |
| 180 | ```bash |
| 181 | gt checkout <first-branch> |
| 182 | gt track -p main |
| 183 | gt restack |
| 184 | ``` |
| 185 | |
| 186 | ### Run Validation |
| 187 | |
| 188 | After creating each PR, run appropriate linting, building, and testing: |
| 189 | |
| 190 | 1. Refer to the project's CLAUDE.md for specific commands |
| 191 | 2. If validation fails, fix the issue, stage changes, and use `gt modify` |
| 192 | |
| 193 | --- |
| 194 | |
| 195 | ## Submitting and Updating PRs |
| 196 | |
| 197 | ### Submit the Stack |
| 198 | |
| 199 | ```bash |
| 200 | gt submit --no-interactive |
| 201 | ``` |
| 202 | |
| 203 | ### Update PR Descriptions |
| 204 | |
| 205 | After submitting, use `gh pr edit` to set proper titles and descriptions. |
| 206 | |
| 207 | **IMPORTANT:** Never use Bash heredocs fo |