π Overview
The # symbol is commonly used in Git commit messages on platforms such as GitHub, GitLab, and Azure DevOps to reference an Issue or a Pull Request (PR). While Git records the commit message exactly as written, the hosting platform interprets the # followed by a number and turns it into a clickable link.
Important
π― Learning Objectives
- Understand what # means in commit messages.
- Learn when to use issue and pull request references.
- Create meaningful commit messages.
- Automatically close issues using GitHub keywords.
- Follow industry best practices.
βWhat Does # Mean?
Whenever you write #123, the number refers to an issue or pull request with ID 123 in the current repository.
Example Commit
fix: resolve login validation (#42)In this example, #42 links the commit to Issue or Pull Request number 42.
π οΈ How to Use #
Step 1 β Create an Issue
Suppose a bug is reported and the repository creates Issue #15.
Issue
#15 - Login button is not workingStep 2 β Create a Branch
Create Feature Branch
git checkout -b fix/login-buttonStep 3 β Make Your Changes
Modify the code and test your solution.
Step 4 β Commit the Changes
Commit Changes
git add .
git commit -m "fix: repair login button (#15)"The commit now references Issue #15.
Step 5 β Push Your Branch
Push Branch
git push origin fix/login-buttonStep 6 β Open a Pull Request
Create a pull request on GitHub to merge your changes into the main branch.
Step 7 β Merge
After review, the pull request is merged. GitHub preserves the relationship between the commit and the referenced issue or PR.
π€ How GitHub Automatically Understands #
GitHub scans commit messages, pull request descriptions, issue descriptions, comments, and other supported text for patterns like #123. If the referenced number exists in the current repository, GitHub automatically converts it into a clickable link.
Information
Where GitHub Recognizes #
| Location | Automatically Linked |
|---|---|
| Commit Messages | β Yes |
| Pull Request Titles | β Yes |
| Pull Request Descriptions | β Yes |
| Issue Descriptions | β Yes |
| Issue Comments | β Yes |
Example
Commit Message
fix: resolve login validation (#42)If Issue or Pull Request #42 exists, GitHub automatically displays #42 as a clickable link. Clicking it opens the corresponding Issue or Pull Request page, allowing developers to view discussions, code reviews, changed files, and related activity.
How GitHub Determines the Reference
Best Practice
π Complete Workflow
π Common Examples
Reference an Issue
Issue Reference
docs: update README (#18)Reference a Pull Request
Pull Request Reference
feat: add dark mode (#91)Close an Issue Automatically
Automatic Issue Closing
Fixes #18
Closes #25
Resolves #40Tip
π‘ Conventional Commit Examples
| Type | Example |
|---|---|
| Feature | feat: add payment gateway (#120) |
| Bug Fix | fix: correct API validation (#88) |
| Documentation | docs: improve installation guide (#52) |
| Refactor | refactor: simplify authentication (#34) |
| Tests | test: add unit tests (#77) |
| Chore | chore: update dependencies (#102) |
β οΈ Common Mistakes
- Using an issue number from another repository.
- Referencing a non-existent issue.
- Using # without creating an issue or pull request.
- Writing vague commit messages like Update or Fix.
β Best Practices
- Keep commit messages concise.
- Reference related issues whenever appropriate.
- Use one commit for one logical change.
- Follow Conventional Commits if your team uses them.
- Use automatic closing keywords only when the issue is fully resolved.
π Practice Exercise
Imagine your repository contains Issue #35 titled "Add search functionality".
Create a commit message that follows best practices.
Sample Answer
feat: add product search functionality (#35)