Introduction
Managing branches and pull requests (PR) is a crucial part of collaborative software development. With the introduction of GitHub Stacks, managing stacked PRs becomes more intuitive. If you're using Jujutsu (jj), a Git-compatible version control system, you can leverage this feature in an optimized manner. This article explains how to make the most of GitHub Stacks with Jujutsu.
Prerequisites
Before starting, make sure you have the following CLI tools installed:
- git for version management (v2.52.0 or higher)
- jj for advanced version control (v0.43.0 or higher)
- gh for the GitHub command line interface (v2.96.0 or higher)
- gh-stack for managing GitHub stacks (v0.1.0 or higher)
To install the stack extension, use: gh extension install github/gh-stack.
Configuring Jujutsu
Jujutsu offers aliases for managing bookmarks, which is essential for stacked PRs on GitHub. You'll need to create bookmarks for each commit in your stack. Here are some useful commands:
jj b lto list bookmarksjj b s <name> -r <commit>to create or move a bookmarkjj b ato advance the nearest bookmark to the current commit
Adapting revset aliases allows you to fine-tune jj's behavior, such as customizing bookmark advancement to target non-empty and described commits.
Manual Workflows
Once you've set up jj, you can use a few essential subcommands to manage your remote stacks on GitHub:
Creating a Stack
To create a stack, start by creating a bookmark for each commit. Use revset aliases to efficiently navigate between commits.
Adding a Commit to the Top of the Stack
Add a new commit to the top of your stack to maintain a structured workflow. This makes managing and reviewing changes easier.
Managing Commits
Whether you want to add a commit to the bottom or middle of the stack, or even remove a commit, jj commands allow you to do so efficiently. Make sure to regularly sync with GitHub to avoid conflicts.
Merging Your Stack
Before merging, ensure all commits are ready and tests pass. Use gh stack push to send your changes to GitHub. Merging stacked PRs is simpler and minimizes the risk of conflicts.
Conclusion
By using Jujutsu with GitHub Stacks, you can significantly enhance your development workflow. The advanced features of jj allow for fine-tuned commit and PR management, giving you more control and flexibility.
Let's discuss your project in 15 minutes.