This version of GitHub Enterprise will be discontinued on This version of GitHub Enterprise was discontinued on 2020-08-20. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Article version: Enterprise Server 2.18

Creating a permanent link to a code snippet

You can create a permanent link to a specific line or range of lines of code in a specific version of a file or pull request.

This type of permanent link will render as a code snippet only in the repository it originated in. In other repositories, the permalink code snippet will render as a URL.

Code snippet rendered in a comment

Tip: To create a permalink for an entire file, see "Getting permanent links to files."

  1. On GitHub Enterprise, navigate to the main page of the repository.
  2. Locate the code you'd like to link to:
    • To link to code from a file, navigate to the file.
    • To link to code from a pull request, navigate to the pull request and click Files changed. Then, browse to the file that contains the code you want include in your comment, and click View.
  3. Choose whether to select a single line or a range:
    • To select a single line of code, click the line number to highlight the line.
      File with a single line of code selected
      • To select a range of code, click the number of the first line in the range to highlight the line of code. Then, hover over the last line of the code range, press Shift, and click the line number to highlight the range.
        File with a range of code selected
  4. To the left of the line or range of lines, click . In the drop-down menu, click Copy permalink.
    Kebab menu with option to copy a permanent link for a selected line
  5. Navigate to the conversation where you want to link to the code snippet.
  6. Paste your permalink into a comment, and click Comment.
    Pasted permalink in a comment in the same repository

Further reading

Ask a human

Can't find what you're looking for?

Contact us