GitHub: Understand issue close keywords with experiments
Tags: beginners, github
Published: 2022-02-14 06:28:25


## GitHub: Understand issue close keywords with experiments

This is my memo about GitHub issues. In this article I will focus on the close key word which allows you to close the linked issue automatically when your pull request is merged with the default branch. I would be happy if you could provide your own usage rules, since I am interested in real life usage.

– [Basic knowledge about close keywords](#basic-knowledge-about-close-keywords)
– [Experiments](#experiments)
– [Learn from an open source project](#learn-from-an-open-source project)

## Basic knowledge about close keywords

These 9 words are close keywords which you can link to issues when you open a pull request.
>  close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved

The issue will be closed when your branch is merged into **the default branch**. In other words, when your pull request is not on the default branch, your pull request is linked to the issue, but the issue won’t be closed automatically after your pull request is closed.

### Syntax

**Pattern1: Issue in the same repository**

    //syntax
    KEYWORD #ISSUE-NUMBER

    // example1
    close #10

    // example2
    I added something to fix #1

**Pattern2: Issue in a different repository**

    //syntax
    KEYWORD OWNER/REPOSITORY#ISSUE-NUMBER

    // example
    resolve Lada496/github-practice#1

**Pattern3: Multiple issues**

    //syntax
    list all linked issues with syntax above

    // example
    resolved #10, resolved #11, fixed resolve Lada496/github-practice#12

### Where to put this keywords

There are two options: 1) the comment on your pull request and 2) your commit message.

**The differences between PR comment and commit message**

The linked issue is automatically closed but the pull request that contains the commit will not be listed as a linked pull request when you use the commit message. On the other hand, the linked issue is automatically closed and the pull request will be listed as a linked pull request when you use PR comment. I will show you what exactly this means in the experiment part.
[**Linking a pull request to an issue - GitHub Docs**](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword)

## Experiments

There are two questions that I wanted to determine: 1) What happens if you merge a branch into the default branch after the branch is merged with another branch linked to an issue? and 2) What exactly differences between PR comments and commit messages.
**Experiment1: On which should the issue linked pull request be?**

condition: the default branch is main

expectation: 
1) your pull request is on the develop branch -> No
2) your pull request is on the main branch -> Yes
3) your pull request is develop and the develop branch is merged to main -> Yes??

1 and 2) are obviously true, but I went through all the patterns during the process and determined whether 3) is true or not.

1) is true
Add close keywords in PR comment
![Add close keywords in PR comment](https://cdn-images-1.medium.com/max/4904/1*zFJisGXPRN0jNtl_05eR9Q.png)

The PR is linked but the issue status is still open
![The PR is linked but the issue status is still open](https://cdn-images-1.medium.com/max/4908/1*t_gA8gJexpC1xes7jOhuPQ.png)

3) is not true
Open PR after develop experiment1–1 was merged into develop
![Open PR after develop experiment1–1 was merged into develop](https://cdn-images-1.medium.com/max/4912/1*v5Fb1r5xACAB-5Cgu0cEnA.png)

The number is 19
![The number is 19](https://cdn-images-1.medium.com/max/3728/1*pB1fWlYr2wZoZVMvH1r8nA.png)

The commit was not linked to this issue nor closed it
![The commit was not linked to this issue nor closed it](https://cdn-images-1.medium.com/max/4076/1*QvOa5DTdJ3ivWyq_FarSRg.png)

2) is also true
PR to the default branch with close keywords
![PR to the default branch with close keywords](https://cdn-images-1.medium.com/max/4852/1*b2F8xNGBSVzeyaY3qwaoqA.png)

The issue was automatically closed
![The issue was automatically closed](https://cdn-images-1.medium.com/max/3628/1*JPUl2oowe-y0aOd5538pUg.png)

**Experiment2: Where to put closing key words**

1)commit message

when you put a close keyword in the commit message
![when you put a close keyword in the commit message](https://cdn-images-1.medium.com/max/4880/1*YOaaHwQYq4TJ8F-YyKKOGg.png)

You will go to the commit history page when you click the link
![You will go to the commit history page when you click the link](https://cdn-images-1.medium.com/max/4028/1*hNUjlmQJaljiXgNIQIQiZw.png)

2)PR comment
when you put a close keyword in the PR comment
![when you put a close keyword in the PR comment](https://cdn-images-1.medium.com/max/4880/1*YOaaHwQYq4TJ8F-YyKKOGg.png)

You will go to the PR history when you click the link
![You will go to the PR history when you click the link](https://cdn-images-1.medium.com/max/4052/1*sVBmP6n2vXST0waIqCjkdw.png)

## Learn from an open source project

I visited an open source project ([React bootstrap](https://github.com/react-bootstrap/react-bootstrap)) to see how they use issues.  I was especially interested in which is better to put close key words. As a result, they use both.

These are typical examples.
[**Missing export for ModalHeader · Issue #6226 · react-bootstrap/react-bootstrap**](https://github.com/react-bootstrap/react-bootstrap/issues/6226)
[**Tabs component has no Fade transition by default · Issue #6232 · react-bootstrap/react-bootstrap**](https://github.com/react-bootstrap/react-bootstrap/issues/6232)
[**When a tooltip is visible and you start scrolling, the tooltip appears above other elements. ·…**](https://github.com/react-bootstrap/react-bootstrap/issues/6209)

However, the sample size is too small to conclude that this is the best practice. Therefore please tell me if you have any opinion about it.

Thank you for reading :)

The original article is [here](https://medium.com/towardsdev/github-understand-issue-close-keywords-with-experiments-18e86b20a0d4)