DEV Community

Cover image for How to automatically close your issues once you merge a PR
Michelle Mannering for GitHub

Posted on • Updated on

How to automatically close your issues once you merge a PR

It's really annoying go through all your issues, and close each one once a feature request or bug report has been completed. The pull request gets merged and then you gotta go find the issue that it corresponds to... way too much time.

Now GitHub has given you a way to automatically close your issues once a pull request has been merged. Let me show you how.

Step 1. Create a pull request

Like you usually do, open your pull request as normal.

Go to your repository, make some changes and open a pull request, but don't click "Create pull request" yet:

Image description

Step 2. Tag the relevant issue

Before you click "Create pull request", we need to link the relevant issue to the pull request so that the correct issue is automatically closed.

    1. Write part of your commit message as usual:

Image description

    2. Add a "linking" keyword to your commit message:

Image description
You can see above here, I've used "closes" (underlined). There are several keywords you can use including:

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved
    3. Tag the relevant issue by typing `#` on your keyboard and selecting or typing in the number of the issue you want to link to:

Image description

Step 3. Merge and close your pull request

Now that you have all the necessary messages and tags, you can go ahead and merge the pull request as usual.

    1. Click "Merge pull request":

Image description

    2. You should see the message that your pull request has been successfully merged:

Image description

You can delete your branch now if you like.

Step 4. Issue is automatically closed

When you navigate back to the relevant issue, you'll see that it is now automatically closed:

Image description

You'll also see the pull request is mentioned in the issue history, and there's a message at the top which reads "Fixed by #96". This means the issue has been resolved by pull request number 96.

Automatically closing issues

I hope this short tutorial gives you a little more control and automation over your repositories on GitHub.

If you'd like to see this as a video, check out our YouTube Short:

There are also other ways you can automatically close issues. Read up on them all in the GitHub Docs.

Top comments (0)