git-stack-cli v2.1.2
git-stack-cli
- ✨ Stacked diffs for
git - 🚀 Simple one-branch workflow
- 🎯 Interactively select commits for each pull request
- 💬 Group commits for focused code review
- 🌐 Use the official GitHub CLI
- ♻️ Automatically synchronize each pull request in the stack
- 💪 Work seamlessly with GitHub's interface
- 🚫 Avoid juggling mutiple branches and complex rebasing
- 📚 Preserve your detailed commit history
- ⚡ Faster, in-memory rebase via
git revise
Demo
Install
Install via Homebrew to ensure the official Github CLI and git revise dependencies are installed automatically
brew install magus/git-stack/git-stackIf you prefer to use npm you will need to install the official Github CLI and git revise dependencies separarely
brew install gh brew install git-revise npm i -g git-stack-cli
Usage
git stack # group and sync commits in branch to Github
git stack --check # print status only, skipping rebase and sync to Github
git stack --verbose # print more detailed logs for debugging internals
git stack --no-verify # skip git hooks such as pre-commit and pre-push
git stack help # print a table of all CLI argumentsEditing existing commits and pull requests
Sometimes you want to add changes to an existing commit or pull request.
With git-stack this is as simple as amending the commit.
git add -pyour changes to the stagegit stack logto find the relative commit number you want to amendgit stack fixup <number>to amend the specific commit with your staged changes.
git add -p
git stack log
git stack fixup 2Running git stack afterward will update any existing pull requests with your changes.
Syncing with remote
To update your local branch with the latest changes in the remote branch (e.g. master, main)
git stack rebaseCustomizing branch name
By default git stack generates a unique branch name such as gs-3cmrMBSUj.
You can specify a prefix for the generated branch name by using either the environment variable or the command line option.
In the example below branches would be generated such as dev/magus/gs-3cmrMBSUj.
GIT_STACK_BRANCH_PREFIX="dev/magus/" git stack
git stack --branch-prefix="dev/magus/"Why?
The goal of git stack is to combine the simplicity of developing in a single branch in order to preserve your commit history while also grouping commits into pull requests for code review.
Often pushing all your commits to a single pull request is the simplest and fastest approach to development. This comes at a price, your teammates have to review larger, less related pieces of code and you will lose some of your atomic commit history if you "Squash and merge".
When you decide to break changes up into multiple diffs that depend on one another this process is commonly referred to as stacked diffs (pull requests that depend on other pull requests).
This approach is popular at many major companies such as Twitter, Facebook, etc.
Managing stacked diffs manually involves managing multiple local branches, jumping between them, rebasing, etc.
This process gets even more complicated when you start getting feedback in code review and have to update individual branches.
Managing even a few stacked diffs requires a relatively strong knowledge of git, even with tricks like --update-refs.
How is this different than x
ghstack
git stackautomatically synchronizes each pull request in your stack, as neededgit stackdoes not create local branches (instead it annotates commits locally with metadata to denote groups of commits, e.g.git-stack-id: E63ytp5dj)ghstackrequires rebasing and squashing since each commit creates a pull request, which means you lose commit historygit stackallows developing in a single local branch and selecting groups of commits for each pull requestgit stackadds a clear comment to each pull request in the stack showing the entire stackgit stackdoes not break if you land pull requests through Github directly,ghstackrequires landing from the CLI interfacegit stackuses the official GitHub CLI (gh) instead of personal access tokens
Development
Ensure node --version is the same across both projects you are using to test the git-stack cli
git submodule update --init --recursive
npm i
pnpm run dev
pnpm link --global
git stack --verboseRemove global install
pnpm remove -g git-stack-cliBuild single-file executable
pnpm run compilePublishing
You must update the
versioninpackage.jsonbefore runningpnpm run release. DO NOT usenpm versionor commit the change, the release scripts handle git tags etc.
pnpm run release
# release individually
pnpm run release:npm
pnpm run release:github
pnpm run release:brew10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
1 year ago
1 year ago
10 months ago
9 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago