95

I've seen commit messages that refer to a specific issue / pull request. What is the syntax to include a specific repository's issue or pull request?

AlbertEngelB
  • 16,016
  • 15
  • 66
  • 93
  • There is a great lib on github for creating these links programmatically: https://github.com/doowb/github-issue-template, and a website where you can drop in a few bits of info and it will generate the link: http://doowb.github.io/github-issue-template/ – jonschlinkert Dec 08 '15 at 21:58
  • See also "[Multiple issue and pull request templates"](https://stackoverflow.com/a/48481402/6309)", since January 2018. – VonC Jan 27 '18 at 22:57
  • 1
    Possible duplicate of [Link to the issue number on GitHub within a commit message](https://stackoverflow.com/questions/1687262/link-to-the-issue-number-on-github-within-a-commit-message) – Didier L May 28 '18 at 16:23
  • @DidierL Date-wise, shouldn't the linked question be a duplicate of mine? I can understand closing this for the linked question when looking at upvotes and content (the `Fixes XXXX` syntax wasn't set up when initially asked), I'm more wondering what constitutes a question being a duplicate over an other. I've had similar old questions closed before, but calling this a duplicate isn't _exactly_ correct. – AlbertEngelB May 29 '18 at 03:28
  • Well, the other question is older isn't it? (2009 vs 2014). As you noted it also has more votes, and AFAICT the questions are exactly the same, and the answers present here are covered in the accepted answer over there. – Didier L May 29 '18 at 12:54
  • Oh, you are right! I looked at the incorrect date (edited date vs. created date), whoops! – AlbertEngelB May 29 '18 at 13:34

4 Answers4

104

Use the documented auto-linking format for issues across repositories.

  • Syntax: {owner}/{repository}#{issue_number}
  • Example: mojombo/jekyll#1

When such formatted text is present in a commit message, it's automatically transformed into a clickable link which will redirect one to https://github.com/{owner}/{repository}/issues/{issue_number}

éclairevoyant
  • 392
  • 2
  • 15
nulltoken
  • 64,429
  • 20
  • 138
  • 130
  • That does indeed work! I tried looking through the documentation and couldn't find anything there, thanks for linking. [Example commit with this format.](https://github.com/droppedonjapan/extensions.js/commit/6170afadd91684a1b8043ea0f5bc9d9322fcb54e) – AlbertEngelB Apr 11 '14 at 18:46
  • 11
    The provided syntax works for linking across repositories (ie. a commit in repo B linking to an issue in repo A). When pointing at issues in the same repository, you can use the short syntax `#{issue_number}` – nulltoken Apr 11 '14 at 19:16
  • Nice! Thanks for the clarification, it is definitely very useful. – AlbertEngelB Apr 11 '14 at 19:24
  • 5
    This is good for issues, but I don't see anything about linking to a Pull Request. – bryanbraun May 12 '15 at 18:56
  • 2
    @bryanbraun This syntax also works for Pull Requests. – nulltoken May 12 '15 at 18:57
  • 2
    @nulltoken Precisely what is the syntax for citing (and linking) to a pull request? If `mojombo/jekyll#1` is about issue 1, what is the syntax for pull request 1 ? – Rob Stewart Jul 19 '15 at 16:21
  • 18
    @RobStewart the same. You can't have both issue 1 and pull request 1 in a repo. – nulltoken Jul 19 '15 at 16:37
  • How do I know where this was done if it says "{user} added a commit that referenced this pull request" on PR? – Tarun Kolla Aug 12 '20 at 17:14
38

Github share PR/Issue number use the same sequence.

So, one #number either one PR or one Issue.

Just use #number is OK.

zw963
  • 1,157
  • 15
  • 11
36

Use #1234 in a comment to reference pull request 1234 from the current repo.

geg
  • 4,399
  • 4
  • 34
  • 35
2

For linking to another repository, if you just paste the link to the issue or pull request, say https://github.com/{owner}/{repository}/issues/{issue_number}, GitHub will render it as

[{owner}/{repository}#{issue_number}](https://github.com/{owner}/{repository}/issues/{issue_number})

For example, https://github.com/jlord/sheetsee.js/issues/26 will render as jlord/sheetsee.js#26.

See https://help.github.com/articles/autolinked-references-and-urls/#issues-and-pull-requests

Matt G
  • 248
  • 5
  • 15