Skip to content

Your first stacked Pull Requests

This page will walk you through creating and updating GitHub Pull Requests or GitLab Merge Requests with git-spice. git-spice refers to these as Change Requests (CRs).

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 or GitLab 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 or GitLab 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.

    glab repo create gs-playground --public
    

    If you don't have the GitLab CLI installed, go to https://gitlab.com/projects/new and follow the instructions there.

Create a Change Request

  1. Check out feat1.

    git checkout feat1
    
    gs branch checkout feat1
    
    gs bco feat1
    
  2. Submit the change.

    gs branch submit
    
    gs bs
    
  3. Follow the prompts on-screen to create the CR. 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 CR.

    gs branch submit
    
  3. Follow the prompts on-screen to create the CR.

The new CR will now be stacked on top of the previous one: the remote will show feat1 as the base branch for the CR.

Modify mid-stack

Modify the feat1 branch and update the CR.

  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 CRs in the stack.

    gs stack submit
    

This will push to both CRs in the stack. If one of the branches was not submitted yet, it will prompt you to create a CR for it.

Merge a CR

  1. Open up the CR for feat1 in your browser 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 CR for feat2 to update the pull request if necessary.

    gs branch submit
    

Summary

This section covered:

  • gs branch submit creates or updates a CR for the current branch.
  • gs stack submit creates or updates CRs for the entire stack.
  • gs repo sync syncs the stack with the trunk branch, deletes merged branches, and rebases the remaining branches.

Next steps