View as Markdown

Setup

Install Mergify CLI and configure your repository for stacked PRs.


  1. Install the Mergify CLI, see the CLI installation guide for instructions.

  2. GitHub authentication: Stacks needs access to create PRs. Either:

    • Set the GITHUB_TOKEN environment variable, or
    • Install the GitHub CLI and run gh auth login
  3. Enable “Automatically delete head branches in your GitHub repository settings (Settings > General > Pull Requests). When a stacked PR merges, this cleans up its remote branch automatically so the next PR in the chain can rebase onto main cleanly.

GitHub setting: Automatically delete head branches

Run the setup command in your Git repository:

Terminal window
mergify stack setup

This installs:

  • A commit-msg Git hook that automatically generates a Change-Id for every new commit. The Change-Id is how Stacks tracks the relationship between your local commits and their GitHub pull requests.

  • A pre-push hook that warns you if you accidentally use git push instead of mergify stack push.

Mergify CLI provides AI skills that teach coding agents how to work with Stacks — so they automatically use mergify stack push instead of git push, amend commits instead of creating fixup commits, and follow stack conventions.

This works with Claude Code, Cursor, and many other AI agents:

Terminal window
npx skills add Mergifyio/mergify-cli

Install as a Claude Code plugin

Section titled Install as a Claude Code plugin

From the official marketplace:

/plugin install mergify@claude-plugins-official

Or from the repository:

/plugin marketplace add Mergifyio/mergify-cli
/plugin install mergify

Create a test commit to confirm the hook is active:

Terminal window
echo "test" >> test.txt
git add test.txt
git commit -m "test: verify stack setup"

Check the commit message:

Terminal window
git log -1

You should see a Change-Id trailer at the bottom of the message:

test: verify stack setup
Change-Id: Ia1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2

Clean up the test commit if you don’t need it:

Terminal window
git reset HEAD~1

These optional Git config settings let you customize Stacks behavior:

SettingDefaultDescription
mergify-cli.stack-branch-prefixstack/{username}Prefix for remote branch names
mergify-cli.stack-create-as-draftfalseCreate PRs as drafts by default
mergify-cli.stack-keep-pr-title-bodyfalseDon’t overwrite PR title/body on updates

Example:

Terminal window
git config mergify-cli.stack-create-as-draft true

Head to Creating Stacks to push your first stack.

Was this page helpful?