Updating Stacks
Amend, reorder, add, or remove commits in your stack.
After pushing a stack, you’ll need to make changes: responding to review feedback, adding commits, rearranging order, or squashing. This page covers every common scenario.
In all cases, the workflow is the same: edit your stack locally, then run
mergify stack push to sync with GitHub. Stacks ships dedicated commands for
every common history rewrite, so you don’t have to drive git rebase -i by
hand.
Each editing command accepts a commit as either a short SHA or a
Change-Id prefix. Most of them also support
--dry-run (-n) to print the plan without touching your branch.
Amend the Latest Commit
Section titled Amend the Latest CommitMake your changes, then amend:
git add src/api/users.pygit commit --amendThe Change-Id is preserved automatically. Then push:
mergify stack pushOnly the PR corresponding to the amended commit is updated.
Edit a Commit Mid-Stack
Section titled Edit a Commit Mid-StackTo modify a commit that isn’t at the top of your branch, point
mergify stack edit at it. Pass a short SHA or Change-Id prefix and the rebase
pauses on that commit:
mergify stack edit a1b2c3dGit stops at the target so you can make changes:
# Make your changesgit add src/models/user.pygit commit --amendgit rebase --continueThen push:
mergify stack pushOnly the amended commit’s PR (and any later PRs whose content shifts) is updated.
Reword a Commit Message
Section titled Reword a Commit MessageTo change a commit’s message without touching its contents:
mergify stack reword d4e5f6a -m "feat: add user registration API endpoint"The Change-Id is preserved, so the PR keeps its identity. Because Stacks derives the PR title and body from the commit message, the corresponding PR’s title and body update on the next push.
Reorder Commits
Section titled Reorder CommitsList every commit in the order you want, by SHA or Change-Id prefix:
mergify stack reorder d4e5f6a a1b2c3d g7h8i9bTo move a single commit without listing the whole stack, use move with
first, last, before, or after:
mergify stack move g7h8i9b firstmergify stack move a1b2c3d after d4e5f6aThe PRs re-chain automatically when you push.
Add a Commit
Section titled Add a CommitJust commit normally anywhere in your branch:
git add src/api/auth.pygit commit -m "feat: add authentication middleware"On the next mergify stack push, a new PR is created and inserted at the
correct position in the chain.
Remove a Commit
Section titled Remove a CommitDrop one or more commits by SHA or Change-Id prefix:
mergify stack drop d4e5f6aOn push, the orphan remote branch is deleted and the remaining PRs re-chain.
Squash or Fixup Commits
Section titled Squash or Fixup CommitsTo fold a commit into its parent and drop its message, use fixup:
mergify stack fixup g7h8i9bTo combine commits into a target while keeping the target’s message, use
squash. Sources go before the into token, the target after it:
mergify stack squash d4e5f6a into a1b2c3dPass -m to rewrite the resulting message instead of keeping the target’s:
mergify stack squash d4e5f6a into a1b2c3d -m "feat: add user model and endpoint"The surviving commit keeps its Change-Id, so the corresponding PR is updated. The absorbed commit’s remote branch is cleaned up automatically.
Preview Before You Rewrite
Section titled Preview Before You RewriteThe history-rewriting commands (reword, reorder, move, drop, fixup,
squash) accept --dry-run (-n) to print the resulting plan without changing
your branch:
mergify stack reorder d4e5f6a a1b2c3d g7h8i9b --dry-runRecord Why You Amended
Section titled Record Why You AmendedWhen you amend a commit that already has a PR, reviewers see a new revision but not the reason behind it. Attach a note before pushing to explain the change:
git commit --amendmergify stack note -m "address review: rename foo() to bar()"mergify stack pushThe note travels with the stack and appears in the PR’s revision history, so reviewers understand what changed between revisions without diffing SHAs. See Reviewing Stacks for the reviewer’s view.
By default, mergify stack push keeps a revision-history comment on each PR up
to date. Pass --no-revision-history (or set
mergify-cli.stack-revision-history to false) to turn it off.
After a PR Merges
Section titled After a PR MergesWhen the bottom PR in your stack merges into main, bring your local branch
back in sync:
mergify stack syncsync fetches the latest main, detects which commits already merged, drops
them from your branch, and rebases the rest. Then push to update the remaining
PRs:
mergify stack pushBefore the merge, your stack looks like this:
After PR #1 merges, commit A lands on main. The remaining PRs re-chain:
sync rebases on main, detects that the merged commit is already there, and
skips it. The remaining PRs update as needed on the next push.
Was this page helpful?
Thanks for your feedback!