Back to Resources

How to create GitHub code permalinks

Pin a 40-char SHA blob permalink with #Lstart-Lend, post it via gh --body-file, then prove the stored URL with gh issue view --json.

What this covers

Creating a permanent link to a code snippet is a browser UI flow: select lines, copy the permalink, paste into a comment. Whole-file permanlinks are separate: Getting permanent links to files.

Flowchart
5 linescompact
flowchart TD
    Navigate["Navigate to file in repository"] --> Select["Click line number or range"]
    Select --> Key["Press 'y' hotkey or click '...' menu"]
    Key --> Permalink["URL changes to permanent commit SHA link"]
    Permalink --> Embed["Paste into Issue/PR to render code snippet embed"]
Rendered from Mermaid source with the native ZeroLabs diagram container.
  1. On GitHub, open the repository.
  2. Find the code:
    • From a file, navigate to that file.
    • From a pull request, open Files changed, find the file, click View.
  3. Select lines:
    • Single line: click the line number to highlight it.
    • Range: click the first line number, then hold Shift and click the last line number.
  4. To the left of the selection, open the overflow / menu and click Copy permalink.
  5. Open the conversation (issue, PR review comment, or discussion) where you want the snippet.
  6. Paste the permalink into the comment and click Comment.

Where the snippet renders

DestinationWhat readers see
Comment in the same repositoryExpanded code snippet for that commit
Comment in a different repositoryPlain URL
Markdown file (README, docs)Plain URL (snippets do not expand here)

Rendered Markdown hides line numbers. Load the file without Markdown rendering by appending ?plain=1 to the blob URL, then add #L plus the line (or range) the same way you would for code.

Example pattern:

https://github.com/OWNER/REPO/blob//README.md?plain=1#L14

That highlights line 14 in the plain README.md view.

A normal blob URL on a branch tip moves when the file changes. A permalink includes a commit SHA, so review comments and issue citations keep pointing at the exact lines you meant. Prefer permalinks when you are citing code in a review or bug report.

Further reading

Share