On this page
Stable GitHub file links for documentation depend on what you want readers to see: the latest version of a file or the exact version you reviewed. A branch link follows changes; a commit-pinned link preserves a historical reference, subject to repository access and retention.
This guide shows how to compare the two and review links when files or directories move.
Key Takeaways
- Use a branch link when readers need the current file, but expect path and line references to drift.
- Use a commit permalink when an explanation depends on exact content or line numbers.
- A pinned link can become outdated even while it remains accessible; a branch link can break when a file moves.
- Check links as the intended audience, including users without repository access.
Branch links versus commit permalinks
A GitHub file link identifies a repository, a revision, and a path. The revision can be a branch name or a commit ID:
Branch: https://github.com/OWNER/REPO/blob/BRANCH/path/to/file
Commit: https://github.com/OWNER/REPO/blob/COMMIT_ID/path/to/file
These are URL patterns, not working links. Replace the uppercase components and path with values from the repository. GitHub line fragments such as #L1 or #L1-L3 can point to a line or a range in the displayed file.
| Link | What it follows | What can change |
|---|---|---|
| Branch | The branch’s current contents | The file, line numbers, or path may change; the link may stop finding the file. |
| Commit | A particular snapshot | The referenced content stays tied to that snapshot, but may become outdated or inaccessible. |
A commit permalink is not a guarantee that GitHub will retain or expose the repository and commit forever. Repository deletion, access changes, or changes to commit availability can still make a link unusable.
Advertisement
Compare links in a public repository
The following example uses the public octocat/Hello-World repository and its README file on the master branch. This example and GitHub’s current interface were not verified for this article. Before publishing, consult GitHub’s current documentation on permanent links and confirm the steps below; if the repository or file has changed, use another public repository and file.
-
Open this branch-based file URL in a browser:
https://github.com/octocat/Hello-World/blob/master/README -
Copy the address. It contains
master, so it refers to the file at that branch’s current revision. -
In the file view, try GitHub’s commonly used
ykeyboard shortcut to switch to a permalink. Interface details and shortcut availability can change; check the current GitHub documentation if it does not work. -
Copy the resulting address. Confirm that the revision is now a commit ID rather than
master, and that the file path is still correct. Open it in a new tab to check it. -
If you need a line reference, add or select the appropriate line anchor, then reopen the final URL. For example,
#L1refers to the first line. Confirm that the selected line is the one your text describes.
The two URLs may display identical content initially. If a later commit changes the branch’s file, the branch URL can display the newer content; the commit URL still identifies the earlier snapshot. This is a comparison readers can perform themselves, not a change observed during preparation of this article.
Choose the link for the reader’s task
Tutorials and code explanations
Pin links when prose explains a particular implementation, example, or line range. A reader can then compare the explanation with the same snapshot. State the revision or release context in the surrounding text so readers know that the example may not describe the latest code.
If the tutorial is intended to track current behavior, a branch link may be more appropriate. Review it whenever the tutorial or repository changes: a valid URL can still point to lines that no longer support the explanation.
API references
Match the reference to the version readers use. A permalink to source code can substantiate a version-specific behavior, while a current branch can help readers explore ongoing development. Do not present a pinned source snapshot as the current API without checking it against the relevant release and documentation.
Installation instructions
Frequently updated installation instructions usually need a current branch link or another maintained canonical location. Pinning an old file can preserve commands that no longer apply. If instructions are specific to a historical release, label that release and link to its corresponding instructions instead.
When files move
A branch link names a path, not a file’s identity. If a file moves and nothing remains at its old path, the branch link may no longer open it. Update the link to the new path, and consider leaving a maintained pointer at the old location if your repository’s workflow allows it.
A commit permalink retains the old path within its historical snapshot, so it can remain useful for explaining that snapshot. It does not automatically lead readers to the file’s new location.
Advertisement
Review links after a branch or directory change
- Find references. Search documentation, issue templates, and release notes for the old branch name, directory, and filename. Include links in other repositories or published documentation you maintain.
- Check the intended revision. Decide whether each link should follow the updated branch or preserve a historical commit. Do not replace permalinks with branch links automatically.
- Open the full path. Follow redirects if any, but update maintained links to the intended destination rather than depending on an assumed redirect. Check filenames and capitalization against the repository.
- Inspect line anchors. Open each link with its fragment and confirm that the highlighted line or range still supports the surrounding text. Update or remove the anchor if it no longer does.
- Check visibility. Open links in a signed-out or otherwise appropriately permissioned session. A link that works for a maintainer may fail for an external reader of a private repository.
- Review meaning, not just status. A link can load successfully yet show an obsolete instruction or an unrelated line. Compare the destination with the claim and its version context.
- Record ownership. Assign a documentation owner or review point for links that intentionally follow a moving branch, especially installation and onboarding links.
A link checker can help find broken destinations, but it cannot reliably determine whether a valid file or highlighted line still says what your documentation claims.
Common Mistakes
- Pinning everything. A stable historical link may be the wrong destination for readers who need current instructions.
- Using branch line numbers as permanent citations. Insertions or deletions above the referenced lines can change what an anchor highlights.
- Assuming a move is harmless. Moving a file can break branch links even when the file still exists elsewhere.
- Testing only while signed in. Repository permissions can conceal access problems for the intended audience.
- Publishing an unverified permalink workflow. GitHub’s interface can change; check its current documentation and try the steps before publication.
Best Practices
Choose the revision deliberately, explain version context when it matters, and review links as part of repository and documentation changes. For important line-specific claims, prefer a commit permalink and periodically check whether the surrounding explanation still needs to refer to that historical version.
Conclusion
Use branch links for information that should follow ongoing changes and commit permalinks for claims about a specific snapshot. In both cases, check the path, anchor, access, and meaning—not just whether the URL opens.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.