iTranslated by AI
How to Get GitHub Permalinks to Code Snippets from VS Code
GitHub has a "permalink" feature that allows you to share files or code snippets by linking them to a specific commit. Unlike links tied to a branch, these permalinks do not point to a different location or disappear when changes are made. Therefore, this feature is useful as a practice for preventing broken links.
- Getting permanent links to files - GitHub Docs
- Creating a permanent link to a code snippet - GitHub Docs
Regarding how to obtain permalinks, the method generally introduced is using the web version of GitHub. However, when you want to get a permalink while reading code in an editor, it is a hassle to intentionally open a browser and look for the corresponding section.
Therefore, this time I investigated how to get permalinks directly from VS Code.
TL;DR
You can obtain a permalink from VS Code by following these steps:
- Install GitHub Pull Requests
- Select the desired code snippet
- Open the Command Palette (
Ctrl+Shift+P) and execute the command "GitHub Issues: Copy GitHub Permalink"
This is the basic method, but below I have also summarized similar features and ways to access the feature without using the Command Palette.
Method
Use the official GitHub extension GitHub Pull Requests.
Since I couldn't find clear documentation for the feature being used, I will summarize the commands that can be used to obtain permalinks and how to access them.
Note that the content introduced below has been confirmed to work with version 0.119.2025092700, which was the latest at the time of writing.
Available Commands
Here are the commands in GitHub Pull Requests that can be used to obtain permalinks:
-
GitHub Issues: Copy GitHub Permalink- Writes a permalink for the selected code snippet to the clipboard.
- Linked to the current commit of the repository open in the editor.
- If nothing is selected, it links to the line where the cursor is.
-
GitHub Issues: Copy GitHub Permalink as Markdown- Writes the permalink to the clipboard in Markdown link format.
- The link text will be as follows:
- If code is selected, it will be the starting line of the selection.
- If no code is selected, it will be the word at the cursor position.
- If no code is selected and there is no word at the cursor position, it will be the file name.
Other related commands are also introduced below:
-
GitHub Issues: Copy GitHub Head Link- Writes a link tied to HEAD to the clipboard.
- Useful when you want a link tied to a branch.
- In a detached HEAD state, it is equivalent to obtaining a permalink.
-
GitHub Issues: Open on GitHub- The browser launches and navigates to the permalink address (allowing you to view the relevant section on GitHub).
Accessing the Feature
1. Using the Command Palette
- Select the location where you want to create a link
- Open the Command Palette (
Ctrl+Shift+P) - Choose a command
-
GitHub Issues: Copy GitHub Permalinketc.
-

2. Right-clicking the Line Number Area
- Right-click the line number
- (For a single line) Right-click the line number of the corresponding line
- (For multiple lines) Select the target code and right-click the line number within that range
- Select
Copy GitHub Permalinketc.

3. Right-clicking the Selected Range
- Select the code
- Right-click the selection
- Select
Copy AsorShare→Copy GitHub Permalinketc.

Other Options
Other methods and related tools (extensions) found are listed below.
-
GitLens
- id:
eamodio.gitlens - You can obtain the remote URL of a file using the
Copy Remote File URLcommand. - You can select a branch using the
Copy Remote File URL From...command. - As far as I investigated, there is no feature to obtain permalinks.
- id:
-
vscode-copy-github-permalink
- id:
hogashi.vscode-copy-github-permalink - An extension that provides a
Copy GitHub Permalinkcommand to obtain permalinks to snippets.
- id:
-
Copy GitHub URL
- id:
mattlott.copy-github-url - Allows you to obtain links based on the current branch, permalinks, and snippet links based on the default branch.
- Includes keybinding assignments.
- id:
Summary
In this article, I introduced the procedures for obtaining permalinks to GitHub code snippets from VS Code using the official GitHub extension and related tools.
At first, I was considering creating an extension, but upon closer investigation, I found that the perfect feature already existed. It was a bit of a hassle to research since there was no documentation, but I'm glad I could summarize it.
Discussion