Git Cheat Sheet · Integrate

Link an issue to a pull request

#12 · Closes #12 (in the description)

Writing #12 in the description of a pull request (GitHub) or merge request (GitLab) creates a link to issue 12. Writing Closes #12 also closes the issue automatically when the pull request is merged into the default branch.

What it does

#12 in the description creates a link to the issue; "Closes #12" also closes it on merge, on GitHub and GitLab alike.

A use case

Your branch fixes the bug reported in issue #12 and you want it to close by itself once the fix is merged.

On the command line

gh pr create --body "Closes #12"
GitHub CLI: creates the pull request with the closing keyword.
glab mr create --description "Closes #12"
GitLab CLI: the same for a merge request.
gh pr edit <number> --body "…"
Changes the description of an existing pull request.
git commit -m "Fix login (fixes #12)"
The keyword also works in a commit message, once the commit reaches the default branch.

In Merathon

  1. In the creation form, type "#" in the description: the project's open issues appear, filtered by number or by a word of the title (others, even closed, are searched on the forge).
  2. Enter inserts #12; Shift + Enter inserts "Closes #12".
  3. If the branch name contains the number (feat/12-…, fix/issue-12), a banner offers "Close on merge".

Frequently asked questions

Which keywords close an issue?

On GitHub as on GitLab: close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved, followed by the number. Case does not matter.

Why did my issue not close?

The keyword only acts when the pull request is merged into the repository's default branch (often main). A merge into another branch leaves the issue open.

How do I close several issues?

Repeat the keyword for each one: Closes #12, closes #15.

See also