---
title: Creating Stacks
description: Walk through creating your first stack of pull requests.
---

This guide walks you through creating a stack from scratch, from starting a
branch to having multiple chained PRs on GitHub.

## Start a new branch

Use the `stack new` command to create a branch that tracks your main branch:

```bash
mergify stack new feat/my-feature
```

This is equivalent to `git checkout -b feat/my-feature --track origin/main`. You
can also create branches however you normally do. Stacks doesn't require its own
branch creation command.

To branch from something other than `main` (a release branch, for example):

```bash
mergify stack new feat/my-feature --base origin/release-v2
```

## Make commits

Work normally. Each commit should represent one logical unit of work, something
that makes sense to review on its own.

For example, building a new API feature:

```bash
# First commit: data model
git add src/models/user.py
git commit -m "feat: add user data model

Define the User schema with fields for auth."

# Second commit: API endpoint
git add src/api/users.py
git commit -m "feat: add user registration endpoint

POST /api/users creates a new user account."

# Third commit: tests
git add tests/test_users.py
git commit -m "test: add user registration tests

Cover happy path, duplicate email, and validation errors."
```

Each commit automatically gets a `Change-Id` trailer. You don't need to do
anything special.

## Push the stack

Run:

```bash
mergify stack push
```

What happens behind the scenes:

1. **Rebases** your branch on the latest `main`, unless the rebase would cost
   you something: an approval it would dismiss, or the bottom PR's place in a
   merge queue the force-push would take it out of. A real merge conflict
   between the bottom PR and `main` overrides both and rebases anyway (see
   [Updating Stacks](/stacks/updating))

2. **Creates a remote branch** for each commit

3. **Opens a PR** for each commit, chained in dependency order

4. **Registers the stack** with GitHub's stacking API, so GitHub shows it as a
   stack of its own, holds the ordering, and lists the stack's members on each
   PR page. GitHub needs at least two PRs to form a stack, so a one-commit push
   doesn't try to register and stays a plain PR. Pass
   [`--no-github-native`](/stacks/setup#configuration) to push without this and
   get a [`Depends-On:` chain](/merge-queue/stacks#mergify-stacks) instead,
   which the [Merge Queue](/merge-queue/stacks) moves as a unit just the same

5. **Posts a stack comment** on every PR showing the full stack, when the stack
   isn't registered and has more than one PR

The full flow, from setup to push:

The result on GitHub: three small, focused PRs instead of one large one. Each PR
contains exactly one commit's worth of changes.

GitHub lists a registered stack on each PR page. If the stack isn't
registered, because you passed `--no-github-native` or the API wasn't
available, each PR in a stack of two or more carries a stack comment showing
where it sits in the chain instead:

## Check your stack

To see the state of your stack at any time:

```bash
mergify stack list
```

This shows each PR, its CI and review status, and a link to GitHub:

:::tip
  Use `mergify stack open` to quickly open a PR in your browser. Name a commit
  to open its PR; run it without one from a terminal and you get an interactive
  picker with `HEAD` preselected.
:::

## Next steps

To update a commit after code review, see [Updating Stacks](/stacks/updating).
For a reviewer's perspective on navigating stacked PRs, see
[Reviewing Stacks](/stacks/reviewing).
