| 1 | --- |
| 2 | title: Pull requests into other branches |
| 3 | description: Open a pull request into a branch other than the default one, change the branch a pull request merges into, and what holds there. |
| 4 | --- |
| 5 | |
| 6 | A pull request merges into its base: the repository's default branch, |
| 7 | unless you choose another. A release branch, a long-running feature branch |
| 8 | or a branch that collects several changes before they reach `main` can |
| 9 | each take pull requests of their own. |
| 10 | |
| 11 | ## Open a pull request into another branch |
| 12 | |
| 13 | 1. Open **Pull requests**, then **New pull request**. Or open **Compare**, |
| 14 | choose the branch to merge into as **base** and yours as **compare**, |
| 15 | then **Open a pull request**. |
| 16 | 2. Beside **into**, choose the branch it should merge into. |
| 17 | 3. Give it a title and a description, and open it. |
| 18 | |
| 19 | A branch can have one open pull request into each base. |
| 20 | |
| 21 | ## Change the branch it merges into |
| 22 | |
| 23 | You need the Write [role](/guides/access-and-roles/) or higher. |
| 24 | |
| 25 | 1. Open the pull request. |
| 26 | 2. Under its title, choose the branch name after **into**. |
| 27 | 3. Pick the branch it should merge into. |
| 28 | |
| 29 | Changing the base is noted in the conversation and is a `pull.base_changed` |
| 30 | event. Whether it is behind, whether it merges cleanly, and its required |
| 31 | checks are worked out again against the new base, and a pull request in |
| 32 | the merge queue leaves it. |
| 33 | |
| 34 | ## What holds in another branch |
| 35 | |
| 36 | A pull request is held to the [rules](/guides/rules/) of the branch it |
| 37 | merges into: every ruleset, the repository's and its workspace's, whose |
| 38 | patterns cover that branch. A ruleset that targets `release/*` holds for |
| 39 | pull requests into `release/1.x` just as one that targets |
| 40 | `~DEFAULT_BRANCH` holds for those into the default branch. |
| 41 | |
| 42 | | | Into the default branch | Into another branch | |
| 43 | | --- | --- | --- | |
| 44 | | Required checks, approvals, being up to date | As the rules covering it ask | As the rules covering it ask; nothing when none cover it | |
| 45 | | [Merge queue](/guides/merge-queue/) | Joins it, when a rule requires it | Never; it merges directly | |
| 46 | | Catching up | Merges the default branch in | Merges its base in | |
| 47 | | Its issue | Closes when it merges | Stays open | |
| 48 | |
| 49 | Merging still needs the Write role. Under **Settings → Rules**, **What holds |
| 50 | for a branch** shows every rule that covers a branch. |
| 51 | |
| 52 | ## g1t's agent and other branches |
| 53 | |
| 54 | When you assign an issue to g1t, its pull request merges into the default |
| 55 | branch. Change the base on its pull request and g1t works against that |
| 56 | branch from then on: it catches up with it, resolves conflicts with it, |
| 57 | and its reviewer compares the change with it. `@g1t` on such a pull |
| 58 | request works against its base too. |
| 59 | |
| 60 | ## From the API |
| 61 | |
| 62 | - `base` on `POST /repos/{owner}/{name}/pulls` (`pull_request` `create`) |
| 63 | opens it into that branch. Leave it out for the default branch. |
| 64 | - `base` on `PATCH /repos/{owner}/{name}/pulls/{number}` |
| 65 | (`pull_request` `update`) changes it. |
| 66 | - `base` filters `GET /repos/{owner}/{name}/pulls` (`pull_request` `list`). |
| 67 | - A pull request's `base` names the branch it merges into. |
| 68 | |
| 69 | ```sh |
| 70 | curl -X PATCH https://api.g1t.sh/repos/acme/web/pulls/14 \ |
| 71 | -H "Authorization: Bearer $G1T_TOKEN" \ |
| 72 | -H "Content-Type: application/json" \ |
| 73 | -d '{"base": "release/1.x"}' |
| 74 | ``` |
| 75 | |
| 76 | [Workflows](/guides/actions/) see the base as `github.base_ref` and |
| 77 | `pull_request.base.ref`, and `branches` filters on `pull_request` match it. |
| 78 | A base change starts `pull_request` workflows with the `edited` activity |
| 79 | type. |
| 80 | |
| 81 | [Dependency updates](/guides/dependency-updates/) open their pull requests |
| 82 | into an entry's `target-branch`. |