Copy links to files in their online Git repositories from inside Visual Studio Code.
Works with:
- Azure DevOps Cloud and Server
- Bitbucket Cloud and Server
- GitHub and GitHub Enterprise
- GitLab (SaaS, Community Edition and Enterprise Edition)
- Visual Studio Team Services
For on-premise hosts (for example, GitLab CE, Bitbucket Server, etc), there is some configuration required. See below for more details.
To copy a link to the file, right-click on the file's tab and select Copy Web Link to File.
You can also right-click on a file in Explorer panel and select Copy Web Link to File.
To copy a link to a particular line in the file, right-click on the line in the editor and select Copy Web Link to Selection.
If you want to copy a link to a range of lines, just select the lines first.
The commands above will create links using either the current commit hash, the current branch name or the default branch name.
The current commit hash is the default format. This can be changed using the gitweblinks.linkType
setting.
"gitweblinks.linkType": "commit"
The default branch can be specified using the gitweblinks.defaultBranch
setting. The default value is "master".
In addition to the commands mentioned above, there are three commands available in the Command Palette that allow you to create a link in a specific format, rather than using the default format.
If you use an on-premise server, you will need to specify the URLs of those servers in your settings file. You need to specify the base HTTP/HTTPS URL of the server, and if you use SSH, the base SSH URL.
Make sure you include any port numbers (if it's not port 80) and context paths.
"gitweblinks.gitHubEnterprise": [
{
"http": "https://local-github",
"ssh": "git@local-github"
}
]
"gitweblinks.gitLabEnterprise": [
{
"http": "https://local-gitlab",
"ssh": "git@local-gitlab"
}
]
"gitweblinks.bitbucketServer": [
{
"http": "https://local-bitbucket:7990/context",
"ssh": "git@local-bitbucket:7999"
}
]
"gitweblinks.azureDevOpsServer": [
{
"http": "https://local-devops",
"ssh": "git@local-devops"
}
]
This extension requires Git to already be installed and on your PATH.
There are three types of links that can be produced, and each have their advantages and disadvantages.
This is the default format, and will create a link using the current commit's hash.
This is great for producing permalinks, but it can lead to 404s if your current commit hasn't been pushed to the remote.
This will create a link using the name of the branch that is currently checked out.
This is good if you only need the link to be useful for a short period of time (for example, sharing a link via email or instant messaging), but it's not great for producing permalinks - if the code on that branch changes in the future, the link maybe become invalid.
This will create a link using the name of the default branch, rather than the name of the branch that is currently checked out. The name of the default branch can be set using the gitweblinks.defaultBranch
setting (the default is "master").
Like the "branch" type, this type of link is also useful for sharing via email or instant messaging, but because it uses the default branch name rather than the name of the current branch, it's particularly useful if you've created a branch locally that does not exist on the server.
The only caveat with this type of link is that the code on the branch that is currently checked out might be different to the code on the default branch, which may lead to an invalid link.