Your first stacked Pull Requests¶
This page will walk you through creating and updating GitHub Pull Requests with git-spice.
Prerequisites¶
-
Create a stack of branches. For this tutorial, we'll assume the following stack. Go back to the previous page if you need to create it.
-
Set up a GitHub repository.
Optional: Create an experimental repository
If you're following along with the tutorial, you may want to create a new repository on GitHub to experiment with instead of using a real project.
To do this, if you have the GitHub CLI installed, run the following inside your experimental repository:
gh repo create gs-playground \ --public \ --source=$(pwd) \ --push
If you don't have the GitHub CLI installed, go to https://github.com/new and follow the instructions there.
Create a Pull Request¶
-
Check out
feat1
.git checkout feat1
gs branch checkout feat1
gs bco feat1
-
Submit a PR.
gs branch submit
gs bs
-
Follow the prompts on-screen to create the PR. For example:
Stack on top¶
-
Check out
feat2
.gs up
-
Submit a PR.
gs branch submit
-
Follow the prompts on-screen to create the PR.
The new PR will now be stacked on top of the previous one:
GitHub will show feat1
as the base branch for the PR.
Modify mid-stack¶
Modify the feat1
branch and update the PR.
-
Check out
feat1
.gs down
-
Make some changes.
echo "Not bad, how about you?" >> hello.txt git add hello.txt gs commit create -m "follow up"
echo "Not bad, how about you?" >> hello.txt git add hello.txt gs cc -m "follow up"
Info
We use the
gs commit create command here. This will commit to the current branch, and rebase the upstack branches on top of the new commit. -
Update all PRs in the stack.
gs stack submit
This will push to both PRs in the stack. If one of the branches was not submitted yet, it will prompt you to create a PR for it.
Merge a PR¶
-
Open up the Pull Request for
feat1
on GitHub and merge it intomain
. -
Run the following command to sync the stack with the trunk:
gs repo sync
This will delete
feat1
locally, and rebasefeat2
on top ofmain
. -
Submit the PR for
feat2
to update the pull request if necessary.gs branch submit
Summary¶
This section covered:
-
gs branch submit creates or updates a PR for the current branch. -
gs stack submit creates or updates PRs for the entire stack. -
gs repo sync syncs the stack with the trunk branch, deletes merged branches, and rebases the remaining branches.
Next steps¶
- Explore other submit commands:
gs upstack submit, gs downstack submit - Browse the User Guide to learn more