> ## Documentation Index
> Fetch the complete documentation index at: https://lib.findy.co.jp/llms.txt
> Use this file to discover all available pages before exploring further.

# How to write pull requests: templates, granularity, stacks

> Pull request basics and practice: setting up a PR template, standardizing commit messages and titles, judging granularity, and stacks for dependent changes.

## Overview

A pull request (PR) is the mechanism for proposing changes to a repository and
collaborating on them through activities such as review. Changes are proposed
through branches: a PR is opened from the head branch, which contains what to
apply, into the base branch, which is where the changes are applied, so that
only approved changes are merged.

## Commit messages

A commit message is a summary of the changes contained in a commit.
Standardizing how messages are written as a team convention makes it possible
to trace, in a consistent format, which commit in the history changed what.

The [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
format is widely used for this convention: `<type>: <summary>`, with a prefix
that indicates the kind of change.

| Type | Use for | Example message |
| - | - | - |
| `feat` | Adding a feature | `feat: add notification settings to the profile page` |
| `fix` | Fixing a bug | `fix: correct the boundary handling in the date filter` |
| `docs` | Documentation-only changes | `docs: add setup instructions` |
| `refactor` | Restructuring code without changing behavior | `refactor: extract date formatting into a shared function` |
| `test` | Adding or updating tests | `test: add boundary-value test cases` |
| `chore` | Build configuration, dependency updates, and other upkeep | `chore: update dependencies` |

[Semantic Versioning](https://semver.org/) is sometimes used together with
Conventional Commits. A version takes the form `MAJOR.MINOR.PATCH`, where the
version level to bump is decided by the compatibility of the change. It is sometimes
adopted in development where compatibility must be managed, such as libraries
and APIs. Combining the two makes the change content easier to understand
from the commit message and lets the release version be determined
mechanically.

| Version level | Use for | Version example |
| - | - | - |
| `MAJOR` | Backward-incompatible changes | `1.4.2` → `2.0.0` |
| `MINOR` | Backward-compatible feature additions | `1.4.2` → `1.5.0` |
| `PATCH` | Backward-compatible bug fixes | `1.4.2` → `1.4.3` |

When combining the two, prefix the type with the version level, as in
`<level>-<type>: <summary>`. This makes explicit the version level that the
type alone does not determine: a feature addition with a breaking change
becomes `major-feat`, and a small feature addition that does not affect
compatibility becomes `patch-feat`.

A commit message can consist of the one-line `<type>: <summary>` alone. To
explain the background or reason for a change, add a body — and footers as
needed — after a blank line.

```text Summary only theme={null}
fix: correct the boundary handling in the date filter
```

```text With a body theme={null}
refactor: extract date formatting into a shared function

The formatting logic duplicated across screens had drifted apart in three
places, so it is consolidated into a shared function.
```

```text With Semantic Versioning theme={null}
major-feat: change the notification list API response to a paginated format

Returning every notification in a single response cannot keep up with the
growth of notifications, so the response is changed to a paginated format.

BREAKING CHANGE: the top level of the response changes from an array to an
object, so clients must read notifications from the items array.
```

## Titles

A PR title is a one-line summary of the change. Titles appear in PR lists,
notifications, and the history after merging, so standardize a style that lets
readers identify the change without opening the description.

Base the title on the commit messages, using the same Conventional Commits and
Semantic Versioning formats. For a PR with a single commit, reuse the commit
message as the title; for a PR with multiple commits, choose the type and
summary that represent the change as a whole.

## Template

A PR template is a Markdown skeleton that is automatically inserted into the
description field when a PR is created. With a template in place, the structure
of the description — overview, changes, verification — stays consistent across
PRs, and the information reviewers need is codified as a rule in advance.

**1. Create the template file**

Add `.github/PULL_REQUEST_TEMPLATE.md` to the repository.

**2. Write the skeleton**

Lay out the information reviewers need, separated by headings and comments.

````markdown theme={null}
## Overview
<!-- State concisely what this PR does -->

## Background / Purpose
<!-- The background that made this change necessary and the goal it serves -->

## Changes
<!-- Bullet list of changes, one item per logical unit -->
-

<!-- If generative AI wrote the code, record the prompt you used -->
<details><summary>Prompt used</summary>

### LLM model used
<!-- e.g., GPT-5.1-Codex, Claude Sonnet 4.5, Gemini 3.0 Pro -->

### Prompt
```markdown

```
</details>

## Test plan
<!-- Check the tests you ran -->
- [ ] Added or updated unit tests
- [ ] Confirmed all existing tests and CI pass

## How to verify
<!-- Steps for reviewers to verify the behavior, and what has been checked -->
- [ ] Exercised the affected feature locally and confirmed it behaves as expected
- [ ] Confirmed surrounding features in the affected area still work

## Related issue
<!-- The issue this PR addresses (title and number) -->

## Notes
````

**3. Merge it into the default branch**

The template takes effect only once it exists on the default branch. PRs
created after the merge get the skeleton inserted into their description
automatically.

> [!TIP]
>
> Review the template regularly. Remove sections nobody fills in. If there are
> items that come up often as questions in review, add them as sections.

## Draft

A draft is a PR state that signals the work is not yet ready for review. While
a PR is a draft it cannot be merged, so unfinished changes are never pulled in
by accident.

Opening a PR as a draft before the work is finished lets you gather feedback
on the direction of the implementation and design early, over the diff of the
actual code. Unlike aligning through documents or conversation, the discussion
is grounded in working code, so you and the reviewers reach a shared
understanding at an early stage.

Once the feedback you need is in and the understanding is aligned, you can
either continue working on the same PR, or close the draft and open a new PR
from scratch. The cost of changing direction grows as the work progresses, so
a draft is an effective way to turn back early and keep the sunk cost to a
minimum.

Select "Create draft pull request" when opening the PR, and switch it out of
the draft state with "Ready for review" once it is ready.

## Granularity

Pull request granularity is whether a single PR concentrates on one thing — the
uniformity of its change content. It is measured by whether the changes are
uniform, not by the number of lines or files in the diff.

### The difference between size and granularity

Size (lines and files changed) and granularity (uniformity of the change
content) are different measures, and granularity is the one that drives the
split decision. The test is whether the PR's change content is uniform — the PR
concentrates on one thing — not how large the diff is.

| Example change | Size | Appropriate? | Reason |
| - | - | - | - |
| Bulk rename of a function used in 10,000 places | Large | Appropriate | The change content is uniform, so one PR is fine |
| Data fetching, transformation, and rendering implemented together | Small–medium | Inappropriate | Different kinds of changes are mixed, so split it |
| A 20-line bug fix plus an unrelated "while I'm here" refactor | Small | Inappropriate | Two different changes are mixed, so split it |

### Why granularity matters

A focused diff narrows the scope that has to be reviewed. For the same total
amount of work, reviewing one change ten times is lighter for both the author
and the reviewer than reviewing ten changes in one PR.

> [card] Faster review
>
> A diff with uniform change content fits in a reviewer's head, so review stops
> being deferred and finishes in minutes.

> [card] Clean reverts
>
> Reverting a PR with a single, uniform change rolls back exactly that change and
> nothing else.

> [card] Fewer conflicts
>
> Short-lived branches are less likely to run into conflicts.

> [card] Faster root-cause
>
> A PR with uniform change content also has a narrow impact area, so isolating
> the cause during an incident is fast.

A large, mixed PR produces a negative cycle: it raises the reviewer's cognitive
load, review is deferred, the branch lives longer, conflicts accumulate, and the
next review is harder still.

Granularity also matters for context management when AI agents do the work.
Having an agent handle multiple requirements or unrelated changes in the same
context spreads its attention and lowers precision. Splitting the work into PR
units with uniform change content lets the agent focus its limited context on
one thing, raising the accuracy of both implementation and review.

### Tips for getting granularity right

#### Break work down first

Decompose the work into independently workable tasks before writing code, so
each task maps to one PR. See [Task Breakdown](https://lib.findy.co.jp/development/task-breakdown.md).

#### When in doubt, split smaller

When unsure about the right granularity, choose the smaller one. Discussing
granularity within the review exchange aligns expectations with the reviewer.

Splitting a PR that has already grown large is harder than starting small and
coarsening the granularity later. When in doubt, ship small and flesh the work
out incrementally.

#### Review first

Finer granularity creates more moments where the next piece of work cannot start
until a merge lands. If review stalls there, it becomes the bottleneck and slows
down overall development speed. So when a review request arrives, handle it
before your own work.

The context switch of interrupting your own work may be a concern, but reviewing
a well-granulated PR takes minutes — sometimes under a minute — so the cost of
the interruption is small. Keeping granularity right is what lets the
review-first habit take root in the team. See
[Code Review](https://lib.findy.co.jp/development/code-review.md) for what that review actually checks.

#### Keep CI fast

Finer granularity means more PRs, and CI runs grow in proportion. If CI stays
slow, the accumulated waiting before each merge erodes development efficiency
instead.

Aim for runs under 10 minutes, and treat anything over 5 minutes as
slow enough to improve. For concrete techniques, see
[Keep CI fast](https://lib.findy.co.jp/development/ci-cd.md#keep-ci-fast) in CI/CD.

#### Separate deploy from release

Treating the deploy of code and the release of a feature as separate events
lets unfinished work merge without waiting for the whole feature to be done,
so PRs can keep shipping small.

See [Release](https://lib.findy.co.jp/development/release-strategy.md) for details.

## Stacks

A stack is a technique for splitting a series of dependent changes into small PRs stacked on top of each other. Each PR in the stack contains one focused change, and its base is the branch of the PR directly below it instead of the default branch.

Keeping PRs small normally collides with dependencies between tasks. When task B builds on the result of task A, you cannot open B's PR against the default branch until A's PR is reviewed and merged, so you either wait or bundle A and B into one large PR. Stacking resolves this: you branch B off A's branch and open B's PR against A's branch, so both stay small and neither blocks the other.

### How to proceed with tasks

When tasks depend on each other, there are three ways to proceed: wait, bundle, or stack. The following diagrams compare them as branch trees.

#### Wait

Task B cannot start until task A's PR merges. Granularity is preserved, but task B's branch can only be created after task A merges, so the follow-up work stalls while the review is pending.

```mermaid theme={null}
%%{init: {'gitGraph': {'mainBranchName': 'main'}}}%%
gitGraph
  commit id: "released"
  branch task-a
  commit id: "implement task A"
  checkout main
  merge task-a id: "wait for PR-A to merge"
  branch task-b
  commit id: "implement task B"
  checkout main
  merge task-b id: "merge PR-B"
```

#### Bundle

Instead of waiting, tasks A and B are implemented on a single branch and go into a single PR. Nothing stalls, but the diff mixes two intents and grows large, raising the review burden.

```mermaid theme={null}
%%{init: {'gitGraph': {'mainBranchName': 'main'}}}%%
gitGraph
  commit id: "released"
  branch task-a-b
  commit id: "implement task A"
  commit id: "implement task B"
  checkout main
  merge task-a-b id: "one large merge"
```

#### Stack

Branch B off A's branch and point B's PR at A's branch. Both PRs stay small, and B proceeds without waiting for A's review.

```mermaid theme={null}
%%{init: {'gitGraph': {'mainBranchName': 'main'}}}%%
gitGraph
  commit id: "released"
  branch task-a
  commit id: "implement task A (PR-A)"
  branch task-b
  commit id: "implement task B (PR-B)"
```

### How it works

A stack is a chain of branches, and each PR in the stack is called a layer. The bottom branch is based on the default branch, and every branch above is based on the branch directly below it. Each PR targets the branch it was based on, so its diff shows only the changes of its own layer.

```mermaid theme={null}
flowchart LR
  subgraph before["Before merging"]
    direction TB
    b3["PR #3: API"] -->|base| b2["PR #2: service"] -->|base| b1["PR #1: model"] -->|base| bm["main"]
  end
  subgraph after["After PR #1 merges"]
    direction TB
    a3["PR #3: API"] -->|base| a2["PR #2: service"] -->|"base (retargeted to main)"| am["main (includes the model changes)"]
  end
  before -->|"merge PR #1"| after
```

Review proceeds independently per layer. A reviewer of PR #2 sees only the service-layer diff, because the model changes below it belong to PR #1.

Merging proceeds from the bottom up. When the bottom PR merges, GitHub automatically rebases the remaining branches so that the next PR targets the default branch, and the stack shrinks by one layer. You can also merge the entire stack at once by merging the top PR — every PR below it merges with it — or land only the bottom portion and keep working on the rest. See [GitHub Docs](https://docs.github.com/en/pull-requests/get-started/about-stacked-prs) for the platform-side behavior.

This mechanism gives stacks the following benefits.

> [card] Granularity is preserved
>
> Each dependent change stays a single-intent PR instead of being bundled into one large diff.

> [card] No waiting on review
>
> You continue the next layer on top of the previous branch while its review is still in progress.

> [card] Reviews stay small
>
> Each PR shows only its own layer's diff, so every review stays within a reviewer's working memory.

> [card] Dependencies are explicit
>
> The base chain records which change builds on which, so the merge order is visible on the PRs themselves.

What needs attention when operating a stack is keeping the chain consistent. When a lower layer changes after review feedback, every branch above it must be rebased onto the updated branch. The stacking technique itself is not specific to GitHub and has long been workable by hand, but then each rebase and base retarget is manual work. GitHub's native support for stacks automates this as a cascading rebase, triggered server-side from the PR or run locally with the `gh stack` extension. Beyond this automation, another benefit of running a stack on GitHub is that GitHub itself understands that the series of PRs is linked as a stack.

Stacking is for changes that genuinely depend on each other. Independent tasks do not need a stack — open them as separate PRs against the default branch.

### Using gh stack

`gh stack` is a GitHub CLI extension that handles the local workflow for a stack as a unit: it creates and tracks branches in dependency order, keeps them rebased, pushes them, creates and links the PRs, and navigates between layers.

> [!NOTE]
>
> GitHub's server-side support for stacks is in public preview and rolling out to repositories in stages. If `gh stack submit` fails on a repository, the rollout may not have reached it yet.

**1. Install the extension**

```bash theme={null}
gh extension install github/gh-stack
```

**2. Build the branch chain**

Implement each layer on its own branch, branching each new branch off the previous one, and commit. Then adopt the existing branches into a stack, listing them bottom to top:

```bash theme={null}
gh stack init --base main feature/model feature/service feature/api
```

To build the stack as you go instead, run `gh stack init` on the first branch and stack each new layer with `gh stack add`.

**3. Create all PRs at once**

```bash theme={null}
gh stack submit --auto
```

This pushes every branch and creates the PRs as drafts, with each base set to the branch below. Mark them ready for review once the descriptions are filled in.

**4. Merge from the bottom**

Merge the bottom PR first; the PRs above are rebased automatically on GitHub's side. Merging the top PR merges the entire stack at once. To catch your local branches up after merges — fetch, rebase, push, and stack-state sync in one command — run:

```bash theme={null}
gh stack sync
```

### Automating stacks with AI agents

Stacks pair well with AI agent workflows. Once work is broken down into issues with explicit dependencies, an agent can implement the issues in dependency order, stacking one branch per issue, and then create all the PRs in one submit. The human concentrates on reviewing and merging each small layer.

An automated workflow takes a parent issue — the output of [task breakdown](https://lib.findy.co.jp/development/task-breakdown.md) — as its input and proceeds as follows.

**1. Read dependencies from the parent issue**

Fetch the parent issue's sub-issues and the dependencies between them. The parent-child issues and dependency settings created during task breakdown become the input of the automation as they are.

**2. Convert the dependency graph into stacks**

Order the dependency graph so that issues to complete first sit at the bottom, and group the issues connected by dependencies — directly or transitively — into one stack. Groups with no dependency connection between them can be worked on in parallel by multiple agents.

For example, suppose the sub-issues have the following dependencies. Arrows point at the issue depended on (the one to complete first).

```mermaid theme={null}
flowchart RL
  B["Issue B"] -->|depends on| A["Issue A"]
  C["Issue C"] -->|depends on| A
  D["Issue D"] -->|depends on| B
  D -->|depends on| C
  F["Issue F"] -->|depends on| E["Issue E"]
```

This graph converts into the following two stacks.

```mermaid theme={null}
flowchart BT
  subgraph s1["Stack 1"]
    A2["Issue A"] --> B2["Issue B"] --> C2["Issue C"] --> D2["Issue D"]
  end
  subgraph s2["Stack 2"]
    E2["Issue E"] --> F2["Issue F"]
  end
```

Issues A through D form one stack because following their dependencies connects them all. Issues B and C have no direct dependency on each other, but they are connected through A and D, so they are stacked serially within the same stack. The group of issues E and F has no dependency connection to A through D, so multiple agents can implement it in parallel.

**3. Implement while stacking branches**

The agent implements the issues in a stack from the bottom, following the dependency order. Each issue gets its own branch and commits, building a chain where issues and branches correspond one to one. Issues with no dependency on each other, like issues B and C in the example above, can be implemented simultaneously in parallel and then assembled into the chain.

**4. Create the PRs in bulk**

Once the chain is built, `gh stack submit --auto` pushes the whole stack and creates the PRs with the base chain configured.

**5. Humans review and merge from the bottom**

Human work starts here: review each layer's small diff and merge from the bottom. When a lower PR merges, the ones above are rebased automatically on GitHub's side, so the stack does not need manual restructuring after every merge. Once every PR in the stack is approved, you can also merge the entire stack at once by merging the top PR.

The quality of this automation is decided by the quality of the task breakdown it consumes. Issues with explicit requirements, completion criteria, and dependencies are the prerequisite for automating stacks.

## Related pages

> [card] [Code Review](https://lib.findy.co.jp/development/code-review.md)
>
> What a reviewer checks once a request lands, and how self-review and clear
> comments keep the exchange fast.

> [card] [Test Code](https://lib.findy.co.jp/development/testing.md)
>
> What makes a change verifiable in the first place, and how tests keep a PR
> reviewable.

> [card] [Onboarding](https://lib.findy.co.jp/organization/onboarding.md)
>
> Why small pull requests are the fastest way for a new member to learn
> from daily feedback.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.