Open In App

How To Link To The Issue Number On GitHub Within A Commit Message?

Last Updated : 16 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When working on GitHub, it's common to connect your commit messages to specific issues. Doing so helps maintain a clear history of changes, making it easier to track progress, manage work, and communicate with your team. In this article, we'll guide you through the process of linking to issue numbers directly within your commit messages on GitHub.

Linking issues in your commit messages provides several benefits:

  • Traceability: You can easily track which commit resolves or relates to a specific issue.
  • Collaboration: Your team members can quickly see what changes were made to address an issue.
  • Automation: GitHub can automatically close issues when certain keywords are used in your commit messages.

Approach 1: Keyword Method

The Keyword Method is an automated way to link and even close issues in GitHub using specific keywords within your commit message. GitHub recognizes certain keywords that, when combined with an issue number, trigger automatic actions like closing the issue.

Step 1: Identify the Issue Number

Find the number of the issue you are addressing. It's usually displayed prominently on the issue page.

Step 2: Write Your Commit Message

Start with a brief summary of the changes you made.

Step 3: Add the Keyword and Issue Number

Append one of the keywords ("fixes," "closes," or "resolves") followed by the issue number. For example: Fixes #123.

Code Example:

# Staging changes for commit
git add .

Output

Screenshot-2024-08-11-015512
Staging changes for commit
# Committing changes with a linked issue number
git commit -m "Fixes #123: Corrected authentication flow"

Output

Screenshot-2024-08-11-015640
Committing changes with a linked issue number

Approach 2: Manual Method

The Manual Method involves simply linking to the issue number in the commit message without using any special keywords. This method is useful when you want to reference an issue without automatically closing it.

Step 1: Write Your Commit Message

Summarize the changes you made.

Step 2: Include the Issue Number

Add the issue number anywhere in the commit message, preceded by a hashtag (#). For example: Added unit tests (#456).

Code Example:

# Staging changes for commit
git add .

Output

Screenshot-2024-08-11-015512
Staging changes for commit
# Committing changes with an issue number
git commit -m "Added unit tests (#456) to improve code coverage"

Output

Screenshot-2024-08-11-015824
Committing changes with an issue number

Additional Considerations

Multiple Issues:

If a commit addresses multiple issues, we can use the keyword method for each issue or combine them into a single line. For example: Fixes #123, #456.

Code Example:

# Staging changes for commit
git add .

Output

Screenshot-2024-08-11-015512
Staging changes for commit
# Committing changes that address multiple issues
git commit -m "Fixes #123, resolves #456: Refactored the user interface"

Output

Screenshot-2024-08-11-015934
Committing changes that address multiple issues

Article Tags :

Similar Reads