ghstacked.com

CLI: ghs

Stack your PRs. Keep your Git.

A lightweight CLI for GitHub stacked pull requests. Create stacked branches, restack changes, and submit PRs with short commands built on GitHub Stack.

Interactive demo · nothing executes

~/project

ghs add

Underlying command

gh stack add -- B2

Example: you are on untracked B2, created from stack tip A. ghs detects A, checks it out, then asks gh-stack to adopt B2. You finish back on B2.

The demonstration shows the commands ghs runs. Nothing executes in this demo.

Installation

Install once. Stack from your terminal.

Homebrew

version
0.2.0

Tap, then install

  1. brew tap peterlapin/ghs https://github.com/peterlapin/ghs.git
  2. brew install peterlapin/ghs/ghs

Use the explicit tap URL above and the full formula name to install ghs.

Run only if not already configured

  • gh auth login
  • gh extension install github/gh-stack

Prerequisites

Git
Normal Git operations still apply.
Homebrew
Required for this installation method.
GitHub CLI
gh must already be installed.
GitHub authentication
An authenticated gh session.
gh-stack extension
gh stack must already be installed and ready to use.

Homebrew installs only ghs. GitHub CLI, authentication and the gh-stack extension are managed separately. ghs is a compiled Go executable for macOS and Linux on Intel and ARM. You do not need Go or jq installed to run it.

Installation happens in your terminal. There is no browser installer, no curl-to-shell script, and no native Windows package.

Upgrade after installation

brew update
brew upgrade peterlapin/ghs/ghs

Uninstall ghs

brew uninstall peterlapin/ghs/ghs
brew untap peterlapin/ghs

Removing ghs leaves your GitHub CLI and extension setup in place.

Command reference

Short commands. Explicit behaviour.

Bare add detects a parent or guides you through creating a layer. Explicit add arguments pass through to GitHub Stack. By default, submit also opens the current branch’s PR after a successful submission. Use --interactive for the original submit behavior.

Mapping of ghs commands to the gh stack commands they run
CommandRuns
ghs initInitialize a stackgh stack init
ghs addAttach this branch or create the next layerDetect or prompt, then gh stack add
ghs add <arguments>Pass explicit arguments directly to upstreamgh stack add <arguments>
ghs create/ ghs cAdd a layer at the topgh stack add
ghs lsShow a compact stack viewgh stack view --short
ghs viewView the stackgh stack view
ghs checkout/ ghs coCheck out a stack or layergh stack checkout
ghs switchChoose a branch interactivelygh stack switch
ghs upMove toward the topgh stack up
ghs downMove toward the trunkgh stack down
ghs topJump to the top layergh stack top
ghs bottomJump to the bottom layergh stack bottom
ghs trunkCheck out the trunkgh stack trunk
ghs restack/ ghs rRebase stack branches locallygh stack rebase --no-trunk
ghs rebaseFetch and rebase the stackgh stack rebase
ghs syncSynchronize local and remote stategh stack sync
ghs submit/ ghs sCreate draft PRs and open the current PRgh stack submit --auto && gh pr view --web
ghs submit --interactive/ ghs s --interactiveUse the original PR details editor without opening the browsergh stack submit
ghs pushPush active stack branchesgh stack push
ghs reshapeRestructure the stack interactivelygh stack modify
ghs mergeMerge stacked PRsgh stack merge
ghs unstackRemove stack tracking and groupinggh stack unstack

Behaviour notes

  • Bare ghs add attaches an untracked branch above its nearest tracked ancestor. If no unique parent can be inferred from Git history, it asks you to choose one. Attachment requires a clean working tree and a parent at the top of its stack.
  • On a tracked stack tip, ghs add asks for staged changes (the default) or all changes, then a new branch name and a separate commit message. All includes untracked files; staged leaves other changes untouched.
  • If the tracked tip has no commits beyond its parent, gh-stack commits on that branch. ghs explains this and skips the branch-name prompt. Adding in the middle of a stack requires ghs reshape.
  • Guided add reads gh-stack's local metadata directly. gh-stack performs commits and stack writes. Explicit add arguments and create/c keep their original behavior. No Go installation or jq is needed to run ghs.
  • submit --interactive uses the original gh stack submit behavior, with the PR details editor in an interactive terminal and no automatic browser opening. ghs removes --interactive and forwards other arguments unchanged; place it before --.
  • submit uses --auto, which skips the PR details editor and creates new PRs as drafts. On success, the current branch's PR opens in your system browser.
  • Existing PRs keep their draft status. Pass --open to mark PRs ready for review. Help and failed submissions never open the browser; a browser failure returns a nonzero exit status after submission succeeds.
  • sync can push changes. It is not fetch-only.
  • restack operates across the stack locally by default. Use --upstack or --downstack to narrow its scope.
  • create adds at the top; it does not insert a branch anywhere in the stack.
  • reshape opens the underlying interactive restructuring interface, not a commit-amend operation.
  • Continue using ordinary git add and git commit.

How it works

Stacking PRs with your existing Git workflow.

Stacked pull requests split a larger change into smaller PRs that build on each other. Keep working on the next branch while an earlier PR is in review. ghs shortens the commands for this workflow, while GitHub Stack manages the branches and pull requests.

  1. 01

    Run a ghs command

    You type a short, memorable name in your terminal.

  2. 02

    ghs prepares the command

    Aliases map to gh stack commands. Bare add detects a parent or asks which changes, branch name, and commit message to use.

  3. 03

    GitHub Stack performs the operation

    The underlying command does the Git work and maintains stack tracking state.

ghs started as a small Bash wrapper: simple aliases that translated ghs commands into gh stack commands. As guided branch creation, parent detection, and interactive workflows grew, we ported it to Go to keep that logic easier to maintain and test. It still delegates commits and stack management to GitHub Stack.

No additional stack engine, synthetic workspace branch or separate authentication. GitHub Stack remains responsible for stack tracking and Git operations.

ghs forwards command output and arguments. By default, submit skips the PR details editor with --auto, then runs gh pr view --web after submission succeeds. If opening the browser fails, the command reports that failure even though the PR has already been submitted. Use ghs submit --interactive to run the original submit command without --auto or automatic browser opening.