# gt stack: Inspect and Restack a Graphite Stack

> gt stack (and gt restack) shows and rebuilds a Graphite branch stack. Reference for gt log, gt restack, gt sync, and the repo/state errors in CI.

Source: https://latchkey.dev/learn/command-reference/gt-stack  
Updated: 2026-06-30

gt commands like log, restack, and sync inspect and rebuild the stack of dependent branches Graphite tracks.

A Graphite stack is a chain of branches each based on the one below. gt log shows the stack, gt restack rebases it after edits, and gt sync pulls trunk and cleans merged branches.

## What it does

gt tracks parent/child relationships between branches. gt log (or gt log short) prints the stack, gt restack rebases descendants onto their updated parents, and gt sync fetches trunk, restacks, and offers to delete branches whose PRs merged.

## Common usage

```Terminal
# view the current stack
gt log short
# rebuild the stack after amending a lower branch
gt restack
# pull trunk and clean up merged branches non-interactively
gt sync --no-interactive --force
```

## Options

| Command / Flag | What it does |
| --- | --- |
| gt log / gt log short | Print the stack of tracked branches |
| gt restack | Rebase descendant branches onto updated parents |
| gt sync | Fetch trunk, restack, prune merged branches |
| --no-interactive | Do not prompt (fail instead) |
| --force | Skip confirmations (e.g. deleting merged branches) |
| gt track / gt untrack | Add or remove a branch from the stack |

## In CI

gt sync --no-interactive --force is the scriptable form for updating a stack in automation. gt restack can leave you in a rebase conflict; check the exit code and abort with git rebase --abort if a job should not stop to resolve it.

## Common errors in CI

"Could not find a Graphite repo" or "not a Graphite repo" means gt init has not run in this clone. "not authenticated" surfaces if a subcommand needs GitHub access. A restack that stops with "CONFLICT" leaves a rebase in progress; the job must resolve or abort it before continuing.

## Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

```.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### gt stack: Inspect and Restack a Graphite Stack?

A Graphite stack is a chain of branches each based on the one below. gt log shows the stack, gt restack rebases it after edits, and gt sync pulls trunk and cleans merged branches.

### What it does?

gt tracks parent/child relationships between branches. gt log (or gt log short) prints the stack, gt restack rebases descendants onto their updated parents, and gt sync fetches trunk, restacks, and offers to delete branches whose PRs merged.

### In CI?

gt sync --no-interactive --force is the scriptable form for updating a stack in automation. gt restack can leave you in a rebase conflict; check the exit code and abort with git rebase --abort if a job should not stop to resolve it.

### Common errors in CI?

"Could not find a Graphite repo" or "not a Graphite repo" means gt init has not run in this clone. "not authenticated" surfaces if a subcommand needs GitHub access. A restack that stops with "CONFLICT" leaves a rebase in progress; the job must resolve or abort it before continuing.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
