What a GitHub link is and why you need one

A link in GitHub is a URL that points to a specific file, folder, or line of code in your repository. When you share this link with someone, they can jump directly to that exact location without having to navigate through your whole project. GitHub generates these links automatically — you just need to know where to find them and how to copy them correctly.

Links are useful when you're reviewing code with a teammate, reporting a bug in a specific file, or documenting which part of your project does what. Instead of saying "look at the authentication section somewhere in the src folder," you can send a link that opens that exact file at that exact line.

Key Takeaways

  • Every file and folder in GitHub has its own URL that you can copy from the browser address bar or by clicking the copy button next to the file name.
  • To link to a specific line of code, click the line number on the left side of the code editor, then copy the URL from your browser.
  • Links to a range of lines require you to click the first line number, hold Shift, and click the last line number before copying the URL.
  • You can create a permanent link to a specific commit or version of a file so the link always shows that exact code, even if the file changes later.

Copying a link to an entire file

Open your repository on GitHub and navigate to the file you want to link to. Click on the file name to open it in the code viewer. At the top right of the code area, you'll see a button that looks like a clipboard or link icon — hover over it and click "Copy file contents" or look for a three-dot menu with a "Copy permalink" option.

The simplest method is to look at your browser's address bar. The URL shown there is already a direct link to that file. You can copy it straight from the address bar and send it to anyone. When they visit that link, they'll land on the same file you're looking at.

Linking to a specific line of code

Open the file in GitHub's code viewer. On the left side of the code, you'll see line numbers. Click the line number of the code you want to point to. The URL in your address bar will change to include that line number — you'll see something like #L42 at the end, meaning line 42.

Copy the URL from the address bar now. When someone visits this link, the page will load and automatically scroll to highlight that exact line. This is much faster than asking someone to find a specific piece of code by hand.

Linking to multiple lines at once

If you need to point to a block of code that spans several lines, click the first line number you want to include. Then hold Shift and click the last line number in the range. GitHub will highlight all the lines between them, and the URL will update to show the range — for example, #L42-L58 means lines 42 through 58.

Copy the URL from the address bar. Anyone who visits this link will see the entire block highlighted in yellow, making it obvious which section you're referring to. This works even if the block is 20 lines long or just 2 lines.

Creating a permanent link to a specific version

When you link to a file the normal way, the link always shows the current version of that file. If someone edits the file tomorrow, your link will show the new code, not the old code you were pointing to. To create a link that never changes, you need to link to a specific commit instead.

Click the "History" button or icon near the top of the file. This shows you a list of every change made to that file, with dates and who made the change. Find the commit (version) you want to link to and click on it. Now copy the URL from the address bar — this link will always show that exact version of the file, even if the file changes a hundred times later.

You can also link to a specific line within a commit. Use the same process: click the line number while viewing that commit's version of the file, then copy the URL. This creates a link that points to line 42 in the version from March 15th, for example.

Sharing links in pull requests and comments

When you paste a GitHub link into a pull request comment or a regular comment on an issue, GitHub automatically converts it into a clickable link. You don't need to do anything special — just paste the URL and it becomes a link that teammates can click.

If you want to make the link more readable, you can use markdown formatting. Instead of pasting the raw URL, type [description here](URL) where description is what you want the link to say. For example: [authentication logic](https://github.com/yourname/yourproject/blob/main/src/auth.js#L42) will display as a link that says "authentication logic" but points to line 42 of your auth file.

Frequently Asked Questions

Will my link break if someone deletes the file?

Yes. If the file is deleted, the link will show a 404 error. If you need a link that survives file changes, link to a specific commit instead of the current version. Commit links never break because they point to a frozen snapshot of your code.

Can I link to code in a private repository?

Only if the person you're sharing the link with has access to that repository. If they don't have permission, they'll see an error page. Make sure the person has been added to the repository before you send them a link to private code.

How do I link to a folder instead of a file?

Navigate to the folder in GitHub and copy the URL from your address bar, just like you would for a file. When someone visits the link, they'll see the folder's contents — all the files and subfolders inside it.

Can I link to a specific line in the GitHub web editor?

Yes, the same method works. Click the line number while editing the file, and the URL updates to include that line. Copy it from the address bar. The link will work whether the file is being viewed or edited.

What's the difference between a regular link and a permalink?

A regular link points to the current version of a file and updates when the file changes. A permalink (created by linking to a specific commit) always shows the exact code from that moment in time. Use permalinks when you need the link to never change.