Skip to content

stack-pr

stack-pr ⧉ is a tool that helps to manage a PR stack. It creates several PRs out of the commits of a local Git branch.

Installation

Installing and setting up stack-pr involves three simple steps:

  1. Install the official GitHub CLI (e.g. brew install gh on MacOS or official docs ⧉ for Linux)
  2. Run gh auth login and select SSH to authenticate your terminal to GitHub
  3. Install stack-pr with pipx install stack-pr or uv tool install stack-pr
Upgrade stack-pr to newer version

The upgrade command depends on the tool you used to install stack-pr. You can use either pipx upgrade stack-pr or uv tool upgrade stack-pr.

Operate PR Stacks

Create

The tool creates one PR for every commit on your local branch. You have to neither push your branch nor create a PR through GitHub's web GUI; simply create commits on a fresh branch and submit the stack.

  1. Create fresh branch from main

    git switch main
    git pull
    git switch --create interesting-new-branch
    
  2. Create self-contained commits building on each other

    # Some changes...
    git commit --message "First commit"
    # And more changes...
    git commit --message "I require first commit"
    # ...however many commits you need...
    

    Consider to add more lines to your commit message because this will automatically show up as your PR description. 3. (Optional) preview your future PRs

    stack-pr view
    
  3. Create your stack on GitHub

    stack-pr submit
    

PRs are automatically created as drafts and needed to be converted manually.

export is an alias for submit.

Edit

For editing an already created/submitted stack (a PR in the stack), you ammend to the existing commits or insert new commits; this might require an interactive rebase.

As an example, you want to edit the second last commit:

git switch intersting-new-branch
git stash push # Stash your local changes
git rebase --interactive HEAD~2 # Interactive rebase of the last two commits
# In the dialouge, hange `pick` to `edit` for the relevant commit
git stash pop # Get your latest stashed changes
git add --all
git commit --no-edit --ammend
git rebase --continue

After editing the commits, you can preview the changes with stack-pr view and update your stack with stack-pr submit; the relevant GitHub PRs would then be updated or newly created.

Rebasing the stack on main works similarly.

Land

If you have met the requirements for merging/landing the PR(s) (generally all tests green and approving review), simply run stack-pr land. This will:

  • Merge the bottom-most PR in your stack
  • Automatically rebase your remaining PRs
  • You can run stack-pr land again to merge the next PR once CI passes
Landing the PR through GitHub's web GUI requires more work.

If you land the PR through clicking in the web GUI, the other PRs of the stack do not get automatically updated, they are neither rebased nor change their base branch. You will then have to rebase your stack on main and submit the stack again.

git switch interesting-new-branch
git pull origin main
stack-pr submit

Hymenaeus helps to remove the need for repeated reviews.