Skip to content

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.

    main feat1 feat2
  • 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

  1. Check out feat1.

    git checkout feat1
    
    gs branch checkout feat1
    
    gs bco feat1
    
  2. Submit a PR.

    gs branch submit
    
    gs bs
    
  3. Follow the prompts on-screen to create the PR. For example:

$ gs branch submitTitle: branch submit: Fix directory+ref conflictBody: Press [e] to open nvim or [enter/tab] to skipDraft: [y/N]INF Created #261: https://github.com/abhinav/git-spice/pull/261

Stack on top

  1. Check out feat2.

    gs up
    
  2. Submit a PR.

    gs branch submit
    
  3. 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.

  1. Check out feat1.

    gs down
    
  2. 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.

  3. 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

  1. Open up the Pull Request for feat1 on GitHub and merge it into main.

  2. Run the following command to sync the stack with the trunk:

    gs repo sync
    

    This will delete feat1 locally, and rebase feat2 on top of main.

  3. 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