Is it somehow possible to automatically have a link to GitHub issue number in the git commit
message?

- 8,029
- 10
- 53
- 79

- 19,877
- 5
- 42
- 49
-
Related: [Cross-referencing commits in github](https://stackoverflow.com/questions/8376475/cross-referencing-commits-in-github) – Didier L May 28 '18 at 16:24
8 Answers
Just include #xxx
in your commit message to reference an issue without closing it.
With new GitHub issues 2.0 you can use these synonyms to reference an issue and close it (in your commit message):
fix #xxx
fixes #xxx
fixed #xxx
close #xxx
closes #xxx
closed #xxx
resolve #xxx
resolves #xxx
resolved #xxx
You can also substitute #xxx
with gh-xxx
.
Referencing and closing issues across repos also works:
fixes user/repo#xxx
Check out the documentation available in their Help section.

- 2,051
- 2
- 30
- 34

- 27,203
- 7
- 68
- 90
-
5`Fix issue #xxx` doesn't work for me, any ideas? It references the issue, but doesn't close it. – Dennis May 07 '12 at 04:55
-
26
-
1@JamesTomasino that's possible - I've noticed that this hasn't been working for me when I'm working on a branch called `dev`. – Jon Cairns Jan 25 '13 at 13:56
-
@JonathanCairns **EDIT**: Check out the below answer: http://stackoverflow.com/a/12830089/1253944 **ORIGINAL**:The convention for an issue on dev branch would be to either use the url (I believe it gets shortened) or use user/repo/branch/issue/7 or /repo/branch/pull/7. Don't quote me on that. It's something like that though. [Github Blog on Issues 2.0](https://github.com/blog/831-issues-2-0-the-next-generation) – erran Feb 02 '13 at 21:46
-
13i'm not going to be the person who moves this answer from 666 votes to 667, but this was VERY helpful. – jakeatwork Sep 05 '16 at 22:06
-
3Worked for me. The only thing I can say about this is when I see xxx, I assume it is a 3 digit number, but obviously `fixes #9` for instance will work. It would be nice if the answer makes this explicitly clear that it is for any length number and you do not need to pad with zeros. – demongolem Jan 15 '19 at 17:54
-
1The # character will mess up with Vim as it is used for comments, beware! If you do a rebase any text after # may disappear. – Amy Pellegrini Oct 16 '20 at 07:44
-
I think, when a merge request is related to the issue, it doesn't close it automatically on Gitlab, which is cool. – emremrah May 21 '21 at 13:31
-
-
Interesting that for Azure DevOps, typing hash in the commit message brings up the actual list of issues (work items), whereas for github it doesn't. Can something be done in this regard? – dotNET Feb 06 '22 at 12:53
-
1One tip, if using #xxx - don't put them at the beginning of your commit message otherwise you will have an interesting conundrum when you need to do a commit --amend . Git refuses the amend because your commit message looks like a commented line and therefore does not exist. – Matt Warren Nov 19 '22 at 13:59
-
I'm getting `This issue will close once commit ee7ae7e is merged into the 'main' branch.`, and I pushed to the main branch but it's not closing? The commit message was `Add bad word filtering (fix #2)` – LuisAFK May 04 '23 at 17:33
-
`fixes user/repo#xxx` does not work (anymore?) in GitHub Desktop. – Nils Lindemann May 17 '23 at 14:13
-
Worth saying that these keywords are case insensitive (`Close #xxx` works just like `close #xxx`) – philipnye May 24 '23 at 20:41
-
Actually you don't need a prefix for `#xxx`, because GitHub tracks all `#xxx` in text files (for example, `changelog.txt`) in a repo. Even more, if you try to close from a commit comment, then you have to reopen it later if a fix actually does not fix or fixes partially. Better to go to the issue manually, retest it and then close it. – Andry Jun 26 '23 at 06:31
-
Another method is to put the issue full url link: `https://github.com/USER/REPO/issues/NUMBER` – Andry Jun 26 '23 at 07:27
-
Beware of repository rewrite issue: `A repository rewrite involves reappend all backtrack links to rewrited commits with issue links` : https://github.com/orgs/community/discussions/49227 – Andry Jun 26 '23 at 07:29
If you want to link to a GitHub issue and close the issue, you can provide the following lines in your Git commit message:
Closes #1.
Closes GH-1.
Closes gh-1.
(Any of the three will work.) Note that this will link to the issue and also close it. You can find out more in this blog post (start watching the embedded video at about 1:40).
I'm not sure if a similar syntax will simply link to an issue without closing it.

- 2,051
- 2
- 30
- 34

- 398,885
- 90
- 523
- 479
-
48You can just use the number of the issue (for example #456) it will link to the task without closing it. – Matthieu Napoli Apr 10 '11 at 14:39
-
12I would choose "gh-1" over "#1" simply because you never know if the repository gets exported/mirrored to somewhere other than github. Then, the "#1" won't make much sense. – huyz Jun 06 '11 at 16:06
-
2@mipadi: is the `.` after "Closes GH-1` necessary? Also, is it case-sensitive? – Lekensteyn Aug 01 '11 at 09:56
-
1@Lekensteyn: I don't believe the period is necessary. Not sure about case-sensitivity. – mipadi Jan 13 '12 at 17:21
-
`message (closes GH-28)` works for me, not sure if everything is case-insensitive. – Lekensteyn Jan 13 '12 at 18:22
-
`I'm not sure if a similar syntax will simply link to an issue without closing it.` #1 without one of the fixes/closes variations before it will refer to an issue without closing. – memmons Oct 22 '12 at 20:25
github adds a reference to the commit if it contains #issuenbr (discovered this by chance).

- 1,096
- 9
- 7
-
4just tested it, works like a charm, thanks... this is the one that should be marked as correct answer... – opensas Aug 28 '11 at 16:32
-
2this should be part of the accepted answer. sometimes you just want to mention the issue and are not doing anything to it yet. – Hadi KAR Jul 21 '21 at 01:43
You can also cross reference repos:
githubuser/repository#xxx
xxx being the issue number

- 2,037
- 1
- 17
- 14
they have an nice write up about the new issues 2.0 on their blog https://github.blog/2011-04-09-issues-2-0-the-next-generation/
synonyms include
- fixes #xxx
- fixed #xxx
- fix #xxx
- closes #xxx
- close #xxx
- closed #xxx
using any of the keywords in a commit message will make your commit either mentioned or close an issue.

- 2,051
- 2
- 30
- 34

- 4,077
- 22
- 39
In order to link the issue number to your commit message, you should add:
#issue_number
in your git commit message.
Example Commit Message from Udacity Git Commit Message Style Guide
feat: Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequenses of this
change? Here's the place to explain them.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
If you use an issue tracker, put references to them at the bottom,
like this:
Resolves: #123
See also: #456, #789
You can also reference the repositories:
githubuser/repository#issue_number

- 405
- 1
- 5
- 16
-
It makes no sense (and actually annoys me) that they use "feat" as an abbreviation for "feature", especially when at the same time they use "refactor" which is even longer than "feature". – Michel Jung Jul 18 '17 at 07:01
-
@MichelJung you could argue that `feat` is used more often than `refactor`, also there's no obvious abbreviation for `refactor` (`ref` could mean reference, `rf` is too unclear, etc.). – Chris Kraszewski Jun 06 '18 at 16:21
One of my first projects as a programmer was a gem called stagecoach that (among other things) allowed the automatic adding of a github issue number to every commit message on a branch, which is a part of the question that hasn't really been answered.
Essentially when creating a branch you'd use a custom command (something like stagecoach -b <branch_name> -g <issue_number>
), and the issue number would then be assigned to that branch in a yml file. There was then a commit hook that appended the issue number to the commit message automatically.
I wouldn't recommend it for production use as at the time I'd only been programming for a few months and I no longer maintain it, but it may be of interest to somebody.

- 2,211
- 17
- 30
-
I think your answer is trying to address the exact question from the OP, i.e. "a way to **automatically** have a link to the issue added in the commit". All other answers rely on programmer remembering to add "Fixes #..., Resolved #... etc." phrase to the commit and this is not going to happen each time as we know it. Upvoting. – demisx Apr 11 '16 at 18:22
Just as addition to the other answers: If you don't even want to write the commit message with the issue number and happen to use Eclipse for development, then you can install the eGit and Mylyn plugins as well as the GitHub connector for Mylyn. Eclipse can then automatically track which issue you are working on and automatically fill the commit message, including the issue number as shown in all the other answers.
For more details about that setup see http://wiki.eclipse.org/EGit/GitHub/UserGuide

- 21,797
- 8
- 68
- 88