Link to the issue number on GitHub within a commit message
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
GitHub is a powerful tool for version control and collaboration. It not only helps in managing the code but also in tracking issues and feature requests through its integrated issue tracking system. By linking a commit to an issue on GitHub, developers can create a coherent history of changes and a clear audit trail that explains why changes were made.
Linking Commits to Issues
To link a commit message to an issue, you can use GitHub's special keyword syntax. This method connects the commit to the issue, providing more context for the change and automatically updating the issue with a reference to the commit.
Basic Syntax:
When you include certain keywords in your commit message followed by the issue number, GitHub automatically links the commit to the issue. Here are some commonly used keywords:
closefixresolve
For example:
In the above commit message, “resolves #42” tells GitHub to link this commit to issue number 42. When the commit is pushed to the default branch (normally main or master), issue 42 will be closed.
Other Supported Keywords Include:
fixesresolvesclosesfixedresolvedclosed
Benefits of Linking Commits to Issues:
- Clarity: Provides clear documentation of why changes were made, which is valuable for future maintenance and review.
- Automation: Automatically closes the issue when the commit is merged into the default branch, helping in project management and ensuring that completed issues are closed promptly.
- Traceability: Enhances traceability by creating a direct link between code changes and the issue they are intended to address.
Examples of Commit Messages
Here are a few examples of how commit messages can be structured to link them directly to issues:
- Commit that fixes a bug:
- Commit that adds a feature:
- Commit that makes a minor tweak:
Best Practices for Commit Messages
- Conciseness: Keep the commit messages concise but explanatory. It should quickly convey what the commit does and reference an issue if applicable.
- Use Imperative Mood: Begin messages with a verb in the imperative mood to illustrate what a commit does, e.g., "Fix", "Add", "Change".
- Context: Besides referencing an issue, provide additional context for why a change is necessary if it's not immediately evident from the issue itself.
Summary Table
| Keyword | Description | Action on Issue |
| close | Indicates that the commit fixes the issue completely. | Closes the issue when the commit is in the default branch |
| fix | Same as close but often used for bug fixes. | Closes the issue when the commit is in the default branch |
| resolve | Usually used when the issue involves more discussion. | Closes the issue when the commit is in the default branch |
| references | Adds a reference to the issue without closing it. | Keeps the issue open but links the commit to it |
Incorporating these practices into daily development workflows creates a more organized and understandable history in project management, facilitating better collaborations, quicker reviews, and a robust development lifecycle.

