visual-studio-codegithub

Copy Link to Github from vscode


I want to copy a link to github.com from the file/line I have open in vscode.

I found a way to copy a vscode.dev link.

You could modify that link by hand:

https://vscode.dev/github/examplecom/myproject/blob/main/mydir/myfile.go#L91-L98

to:

https://github.com/examplecom/myproject/blob/main/mydir/myfile.go#L91-L98

... but that is not convenient.

How to copy a link to github.com directly?

BTW, "GitLens" is not an answer. I uninstalled that plugin because it constantly wants you to sell something.

In the past I have seen "copy as", but I do not see that any more:

no-more-copy-as-in-vscode


Solution

  • What you're requesting can only be done reliably using a VSCode extension.

    Given what you're asking, it looks like the GitHub linker extension will suit your needs.

    From its description:

    GitHub linker allows you to select a piece of text and create a permanent link to GitHub.com for that piece of text. Just select the text, right click, and you'll see two new options.

    • Copy a permanent link to the clipboard
    • Copy a permanent link and code as markdown

    The second option not only copies the link but also copies the piece of selected text properly wrapped in a markdown code block with the programming language correctly specified.

    Requirements: The file must be tracked in a git repo and the current branch must be pushed to GitHub.com.

    Alternatively, the official GitHub Pull Requests extension provides the Copy Github Permalink and Copy Github Permalink as Markdown actions, according to the associated SO answer linked above.