57

How do I close an issue using a pull request on GitHub? I know about closing multiple issues with a commit message, but it's a different case.

I would like to close the issues not from a commit, but from the description of the pull request. More like

Pull request:

Name: bla bla
Description ... , _fixes_ #123

And when merging the pull request, the #123 to automatically close. Is this possible?

Community
  • 1
  • 1
  • 5
    one can close an issue from the pull request on github when actually doing the `merge`, by adding a description message like `closes #123` or `fixes #242 #111` where `#number == issue number` – Andrei-Niculae Petre Dec 09 '12 at 15:22
  • Have you tried this on a sample repo? Create two issues, have one reference the other with "closed #xxx" and close that one. What happens – random Jan 14 '13 at 22:47
  • 3
    The workflow is the following: you have an issue #111, and a pull request #112. When merging the pull request into a branch (by hitting Merge pull request button), github requires additional info in a textarea and asks you to "Confirm merge". In that textarea, one can add "closes #111" and when hitting Confirm merge, the issue #111 will get closed. Not the ideal way, but it's better than nothing. – Andrei-Niculae Petre Jan 18 '13 at 11:26
  • Then that should be the answer – random Jan 18 '13 at 17:29

2 Answers2

92

As you mention in the comments, the merge from the pull request will result in a commit.
It is on that commit message you can add a "close #xx" in order to trigger the closing of an issue.

However, as mentioned in "Closing multiple issues in Github with a commit message", in GitHub blog post "Closing Issues via Commit Messages" (January 2013), and in the current GitHub docs.

Now when you enter "Fixes #33" in a commit message, issue 33 will only be closed once the commit is merged into your default branch (usually master).

This is super useful because it means the issue's open / closed status will map to your default branch.
If the bug isn't fixed in your default branch, the issue will remain open.
Once the commit with the fix is merged into your default branch the issue will be automatically closed.

When you do make a commit in a non-default branch with the "Fixes #33" syntax, the issue will be referenced with a tooltip:

Closing Issue

You can use any of these keywords to close an issue via commit message:

close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved

As mentioned below by cosmolev (upvoted), the blog post from May 14th 2013 "Closing Issues via Pull Requests" adds pull requests as a way to close an issue:

some issues take more work than a single commit to close.
That's why you can now close an issue from a Pull Request.
All you have to do is include the special keyword syntax (eg. "fixes #5") in the body of your Pull Request.

comment on pull request

the referenced issue will automatically be closed when the PR is merged into the default branch.
It even works across repositories.

As John Eikenberry points out in the comments, the help page "Closing issues using keywords" does mention:

To close multiple issues, preface each issue reference with one of the above keywords.
You must use the keyword before each issue you reference for the keyword to work.

For example, This closes #34, closes #23, and closes example_user/example_repo#42 would close issues #34 and #23 in the same repository, and issue #42 in the "example_user/example_repo" repository.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • nice, didn't know it was fixed. Last time I tried the fixes #33 in a commit, the issue would close. Cool. – Andrei-Niculae Petre Apr 05 '13 at 20:30
  • 2
    @AndreiPetre as mentioned below by cosmolev, and as edited in my answer, pull requests can now close an issue as well. – VonC May 31 '13 at 05:35
  • Small addendum. To close multiple issues in one pull request, you need the keyword before each issue. Eg. `fixes #123, fixes #321, fixes #999` ref: https://help.github.com/en/articles/closing-issues-using-keywords – John Eikenberry Jul 03 '19 at 22:41
  • @JohnEikenberry Thank you. I have included your comment in the answer for more visibility. – VonC Jul 04 '19 at 04:35
14

It's finally possible: https://github.com/blog/1506-closing-issues-via-pull-requests

Just add resolve #18 to pull request message

where 18 is an issue number

Leo
  • 2,097
  • 21
  • 35
  • Interesting. +1. I have included a reference to that blog post in my answer for more visibility. – VonC May 31 '13 at 05:33