git-stack
is a command-line tool for managing stacked git branches — a workflow where you develop
features atop one another, keeping their history clean and rebasing as needed. It tracks
relationships between branches, helps you re-stack and synchronize them, and visualizes your stack
tree.
- Stacked Workflow: Track parent-child branch relationships ("stacks") in your repo.
- Restack: Automatically rebase your branch stack on top of trunk or another branch.
- Status Tree: Visualize your current stacked branches, their hierarchy, and sync status.
- Branch Mounting: Change the parent branch of an existing branch in your stack.
- Diffs: Show changes between a branch and its parent.
- Safe Operations: Prevent accidental data loss by checking upstream sync status.
Build from source (Rust required):
cargo install --path .
This will install a CLI you can use as follows:
git stack <command> [options]
You can invoke git-stack
directly or as a git subcommand:
git stack <subcommand> [options]
-
status
: Show the current stack tree in the repo.- Default, so
git stack
is equivalent togit stack status
.
- Default, so
-
checkout <branch>
: Create a new branch stacked on the current branch, or checkout an existing one in the stack. -
restack [--branch <branch>]
: Rebase the named (or current) branch and its descendents onto their updated stack base (like trunk or a parent feature branch). This command recursively applies to all ancestors of the given branch. -
mount [<parent-branch>]
: Mounts (attaches) the current branch on a different parent branch. -
diff [<branch>]
: Show diff between a branch and its stack parent. -
delete <branch>
: Remove a branch from the stack tree.
git stack status
git stack checkout my-feature
git stack restack
git stack mount new-parent-branch
git stack diff my-feature
git stack delete my-feature
- Stack state is stored per-repo in a YAML file at:
~/.local/state/git-stack/state.yaml
(using XDG state dir conventions).
- A POSIX shell
- git (on your
$PATH
) - Rust (to install/build)
If git stack
reports missing branches or refuses to restack:
- Ensure your working tree is clean (
git status
). - Use standard git commands to resolve any rebase conflicts (
git mergetool
is your friend, followed bygit rebase --continue
), then rerungit stack restack
. - Note that the last-known-good location of the parent branch is stored in the sub-branch in order to allow for cleaner movement of branches