Примечание.
This feature is in public preview and subject to change.
Create stacked pull requests with the gh stack extension in GitHub CLI or on the GitHub website.
Примечание.
Stacked pull requests require all branches to be in the same repository. Cross-fork stacks are not supported.
Creating a stack with GitHub CLI
-
Initialize a stack. This creates and checks out the first branch on top of your trunk branch.
Shell gh stack init auth-layer
gh stack init auth-layer -
Write code for the first layer, then stage and commit your changes.
Shell git add . git commit -m "helpful-commit-message"
git add . git commit -m "helpful-commit-message" -
Add a branch for the next logical unit of work. The new branch is created on top of the current one.
Shell gh stack add BRANCH-NAME
gh stack add BRANCH-NAME -
Write code and commit on the new branch. Repeat for each additional layer.
-
Push all branches to the remote repository and create the stacked pull requests on GitHub.
Shell gh stack submit
gh stack submitEach pull request is created with the correct base branch, so reviewers see only the diff for that layer, and the pull requests are automatically linked together as a stack.
Creating a stack from the GitHub website
You can create a stack without the CLI by setting the base branch of each pull request to the branch below it.
-
Create the first pull request as you normally would. Typically your base would target
main. -
Create the next pull request and set its base branch to the first pull request's branch. Select the Create stack option to link the two pull requests together as a stack.
Once created, the stack shows the pull requests linked together.
- A stack icon at the top of the pull request shows a number indicating which layer you're viewing.
- A stack map appears in the merge box. It shows every pull request in the stack and its status, and lets you navigate to any layer with one click.
-
Repeat for each additional pull request, targeting the branch of the pull request before it.
Turning existing pull requests into a stack
If you already have open pull requests whose branches line up, where each pull request's base branch is the head branch of the pull request below it, GitHub recognizes the chain and shows a recommendation banner offering to turn them into a stack.
-
On any of the eligible pull requests, select the banner to open a dialog that previews the stack, listing each pull request in order from top to bottom.
-
Review the preview and confirm to link the pull requests together into a stack.
Once you confirm, the stack map appears in each pull request's header.
Add to an existing stack from the GitHub website
To add a new pull request to a stack that already exists:
-
Open any pull request in the stack, click in the header, and then click Add to stack.
-
The base branch is automatically set to the head of the top pull request. Select the head branch for your new pull request and select Create pull request.
-
Select Add to stack, to create the pull request.
The new pull request is added to the top of the stack.