githubworkflowpull-request

Automatically closing issue from pull request in GitHub


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?


Solution

  • 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.


    Since Apr. 23rd, 2025, you now have:

    "Users can now choose whether merging linked pull requests automatically closes the issue"

    Linking a pull request to an issue makes it easy for collaborators to see that work for the issue is underway. Today, when a linked pull request is merged, the associated issue is automatically closed.

    But for many teams, merging a PR doesn’t mean the work is done. There might be QA, validation, or follow-up steps before an issue is truly resolved. With this new repository setting, you can choose whether merging a pull request should automatically close its linked issues.

    Repository admins and maintainers can manage this setting under Repository settings → General → Issues. It’s enabled by default to preserve existing

    https://github.com/user-attachments/assets/b38de804-fdfe-4609-91ef-1f468c8cb6e8 -- Shows the repository setting for auto-closing issues