What a GitHub link is and why you need one
A link in GitHub is a URL that points to a specific file, folder, line of code, or entire repository. When you create a link, you give other people a direct path to exactly what you want them to see — whether that's a bug report, a code example, or documentation. GitHub generates these links automatically; you just need to know where to find them and how to format them so they work in README files, issues, and pull requests.
The most common reason to create a link is to reference code from somewhere else in your project. You might link to a specific line in a file so a teammate knows exactly what you're talking about, or you might link to an issue from a pull request to show which problem your code solves. Links keep your project organized and make it easier for people to navigate without getting lost.
Key Takeaways
- GitHub generates shareable links automatically when you click the three-dot menu on any file, folder, or line of code.
- Permanent links include a commit hash so they point to the exact version of the code, even if the file changes later.
- You can link to a single line by clicking the line number, or to a range of lines by shift-clicking from the first line to the last.
- Links work in README files, issues, pull requests, and comments when you paste them as plain text or wrap them in markdown brackets.
How to copy a link to a file or folder
Open your repository on GitHub and navigate to the file or folder you want to link to. Click on the file or folder name to open it. In the top right corner of the file view, you'll see a button with three dots (⋯). Click that button and select Copy permalink from the menu that appears.
GitHub copies a permanent link to your clipboard. This link includes a commit hash — a long string of numbers and letters — that locks the link to this exact version of the file. Even if someone updates the file tomorrow, your link will still point to the version that exists right now. Paste the link anywhere you need it: in a README, in an issue, in a comment, or in an email to a teammate.
If you want a link that always points to the current version of the file (so it updates automatically when the file changes), click the three-dot menu again and select Copy path instead. This creates a shorter link without the commit hash. Use this when you're linking to documentation or a file you expect to update regularly.
How to link to a specific line or range of lines
Open the file you want to link to and look at the line numbers on the left side. Click the line number of the line you want to reference. The line highlights in yellow and the URL in your browser's address bar updates to include that line number. Click the three-dot menu and select Copy permalink to copy the link with the line number included.
To link to multiple lines at once, click the line number of the first line you want, then hold Shift and click the line number of the last line. GitHub highlights all the lines between them in yellow. Copy the permalink as before — the link now includes both the starting and ending line numbers. When someone opens this link, they'll see all those lines highlighted.
This is especially useful when you're reviewing code in a pull request or explaining a bug. Instead of saying "look at the function around line 45," you can send a link that takes them directly there with the exact lines already highlighted.
How to use links in README files and documentation
In a README file or any markdown file in your repository, you can paste a link as plain text and GitHub will turn it into a clickable link automatically. You can also format it using markdown syntax: type the text you want to display in square brackets, followed immediately by the URL in parentheses, like this: [text here](URL).
For example, if you want to link to a specific file, you might write: [See the configuration file](https://github.com/username/repo/blob/main/config.yml). When someone reads your README, they'll see "See the configuration file" as a blue clickable link. This approach keeps your documentation clean and readable while still giving readers a direct path to the code you're referencing.
You can also link to issues and pull requests using the same markdown format. Type [#123](https://github.com/username/repo/issues/123) to link to issue number 123, or just type #123 and GitHub will automatically turn it into a link if you're in the same repository.
How to link from issues and pull requests
When you're writing in an issue or pull request comment, you can link to code the same way you do in a README. Paste the link directly or use markdown formatting. GitHub also recognizes shorthand: if you type #456, it automatically becomes a link to issue or pull request 456 in your current repository.
To link to an issue or pull request in a different repository, use the full format: #456 becomes username/repo#456. For example, alice/project#123 links to issue 123 in Alice's project repository. This is useful when you're working across multiple repositories and need to reference work happening elsewhere.
When you link to an issue or pull request from a comment, GitHub creates a two-way connection. The linked issue or pull request shows that it's been referenced, so anyone looking at that page can see all the places it's been mentioned. This helps keep related work visible across your project.
How to link to a commit
Find the commit you want to link to in your repository's commit history. Click on the commit message or the commit hash (the short string of numbers and letters). This opens the commit details page. Click the three-dot menu in the top right and select Copy permalink. This creates a link to that specific commit that will never change, even if the commit is later rebased or moved.
You can also copy just the commit hash itself and paste it into a comment or issue. GitHub recognizes commit hashes and turns them into links automatically. A short commit hash (the first 7 characters) usually works, but the full hash is more reliable if you're linking across repositories.
Linking to commits is useful when you're explaining why a change was made, reviewing a pull request, or tracking down when a bug was introduced. Instead of describing what changed, you can link directly to the commit and let people see the exact code change.
Common mistakes when creating links
The most common mistake is copying the link from your browser's address bar instead of using GitHub's copy permalink button. The address bar link works, but it points to the current version of the file, not the specific commit. If the file changes, your link will show the new version instead of the version you meant to reference. Always use the three-dot menu and select Copy permalink to get a permanent link.
Another mistake is forgetting that links in markdown need the full URL, not just a relative path. If you type [file](config.yml), the link won't work. You need the full GitHub URL: [file](https://github.com/username/repo/blob/main/config.yml). The exception is shorthand like #123 for issues and pull requests in the same repository — that works without the full URL.
If a link doesn't work, check that the URL is complete and that the file or issue still exists. If you're linking to a private repository, the person clicking the link needs access to that repository or they'll see a 404 error. Public repositories are accessible to anyone with the link.
Frequently Asked Questions
What's the difference between copy path and copy permalink?
Copy path gives you a link to the current version of the file, so it updates when the file changes. Copy permalink includes a commit hash and always points to the exact version of the file as it exists right now. Use copy path for documentation you update regularly, and copy permalink when you want to reference a specific version of code.
Can I link to a private repository?
Yes, but only people with access to that repository can open the link. If someone without access clicks it, they'll see a 404 error. If you need to share code from a private repository with someone who doesn't have access, you'll need to give them access to the repository first or copy the code into a message.
Do links work in commit messages?
Yes. If you type a URL or use markdown formatting in a commit message, GitHub turns it into a clickable link. You can also use shorthand like #123 to link to issues and pull requests. These links appear in the commit details page and in your repository's history.
How do I link to a specific line in a pull request?
Open the pull request and click the Files Changed tab. Find the line you want to link to and click the line number. A comment box appears. You can type your comment there, and the line number is automatically included in the link. Alternatively, click the three-dot menu next to the line number and select Copy permalink to get a shareable link.
Can I link to a branch instead of a specific commit?
Yes. Instead of using a commit hash, you can use a branch name in the URL. For example, https://github.com/username/repo/blob/main/file.js links to the file on the main branch. This link updates as the branch changes. Use this when you want the link to always show the latest version of the file on that branch.