Setup
Install Mergify CLI and configure your repository for stacked PRs.
1. Install the Mergify CLI
Section titled 1. Install the Mergify CLISee the CLI installation guide for full instructions.
Quick install:
curl -fsSL https://raw.githubusercontent.com/Mergifyio/mergify-cli/main/install.sh | sh2. Install skills for your AI coding agent
Section titled 2. Install skills for your AI coding agentMergify ships Agent Skills that teach AI coding agents how to
work with Stacks, so they run mergify stack push instead of git push, amend
commits instead of creating fixups, and follow stack conventions automatically.
Claude Code:
/plugin install mergify@claude-plugins-officialCodex, Cursor, and any other skills.sh agent:
npx skills add Mergifyio/mergify-cliEither command installs the whole bundle, which also covers the merge queue, CI Insights, config validation, and scheduled freezes. See Agent Skills for what each skill does and which token it needs.
3. Configure GitHub
Section titled 3. Configure GitHubStacks needs access to create PRs. Set the MERGIFY_TOKEN or GITHUB_TOKEN
environment variable, or install the GitHub CLI and
run gh auth login. The CLI tries them in that order. See
Authentication for where each token comes from.
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, which is
also what lets GitHub retarget the next PR in the chain onto main. See
Merging Stacked PRs.
4. Initialize your repository
Section titled 4. Initialize your repositoryRun the setup command in your Git repository:
mergify stack setupThis installs:
-
A
commit-msgGit 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-pushhook that warns you if you accidentally usegit pushinstead ofmergify stack push.
Verify It Works
Section titled Verify It WorksCreate a test commit to confirm the hook is active:
echo "test" >> test.txtgit add test.txtgit commit -m "test: verify stack setup"Check the commit message:
git log -1You should see a Change-Id trailer at the bottom of the message:
test: verify stack setup
Change-Id: Ia1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2Clean up the test commit if you don’t need it:
git reset HEAD~1Configuration
Section titled ConfigurationThese optional Git config settings let you customize Stacks behavior:
| Setting | Default | Description |
|---|---|---|
mergify-cli.stack-branch-prefix | stack/{username} | Set the prefix for remote branch names |
mergify-cli.stack-create-as-draft | false | Create PRs as drafts by default |
mergify-cli.stack-github-native | false | Also register the stack with GitHub’s stacking API |
mergify-cli.stack-keep-pr-title-body | false | Don’t overwrite PR title/body on updates |
mergify-cli.stack-revision-history | true | Keep a revision-history comment on each PR |
Example:
git config mergify-cli.stack-create-as-draft truemergify stack push has a flag for each of these (--branch-prefix,
--draft, --github-native, --keep-pull-request-title-and-body and
--no-revision-history) to override the setting for a single push.
--branch-prefix is also accepted by mergify stack list,
mergify stack open and mergify stack sync, which have to look for the same
branches. Setting the Git config once covers all four.
Next Steps
Section titled Next StepsHead to Creating Stacks to push your first stack.
Was this page helpful?
Thanks for your feedback!