On this page
A GitHub file-view link is usually best when readers need to understand a file in its repository context. A raw-file link is useful when they need the file’s contents directly. Choosing the wrong one can make a tutorial harder to follow or cause a download command to retrieve a web page instead of the intended file.
Key Takeaways
- Use a blob URL to show a file in GitHub’s interface, especially when linking to lines of code.
- Use a raw URL when a tool or reader needs the file contents rather than the GitHub page.
- Branch links can change as the branch changes; commit links identify a particular revision.
- Before publishing, check redirects, file availability, and access from the reader’s perspective.
GitHub raw URL vs blob URL
GitHub’s file-view URLs commonly contain /blob/. They show a file inside the repository interface, with context such as its path and, where available, rendered content or syntax highlighting. The word “blob” in this URL does not mean the link returns only the file’s bytes.
A raw URL instead requests the file itself. For example, these illustrate the two forms for a README in GitHub’s public octocat/Hello-World example repository:
File view: https://github.com/octocat/Hello-World/blob/master/README
Raw file: https://raw.githubusercontent.com/octocat/Hello-World/master/README
Here, master is the branch and README is the file path. Treat these as examples to check, not as verified working links: GitHub’s current documentation and live URL behavior could not be checked for this article. Before publication, consult GitHub’s current documentation and open the actual links you intend to use. Prefer copying the file-view URL and using GitHub’s Raw control to obtain the corresponding raw link rather than constructing it by string replacement.
Advertisement
Choose a link for the reader’s task
| Task | File view | Raw file |
|---|---|---|
| Read and understand a file | Usually the better choice: readers get repository context. | Shows or downloads the content without that context, depending on the browser and response. |
| Download with a script | May return GitHub’s HTML page instead of the file. | Usually the appropriate starting point; check the response before using it. |
| Embed content | A page link is not a general-purpose embed. | May work for some resource types, but content type, browser restrictions, access, and the embedding application matter. |
| Point to specific lines | Use a file-view line anchor, such as #L1-L5, and verify it in the interface. | Raw content generally does not provide GitHub’s line-navigation interface. |
| Follow a branch | Shows the file at the branch’s current revision. | Retrieves the file at the branch’s current revision. |
| Pin a revision | Use a file-view link containing the commit ID. | Use the raw link for that same commit. |
For a prose tutorial, link to the file view when readers should inspect surrounding code or navigate the repository. If you also provide a download command, give it a separately checked raw link. Explain what the file is and whether users should inspect it before running or importing it.
A raw link is not automatically suitable for every embed. For example, an image embed needs an accessible image response, and browser security policies can restrict fetching or executing other resources. Test the exact embedding method in its intended environment; do not assume that a URL working in a browser tab will work in an iframe or script.
Branch links, commit links, and line references
A branch URL is convenient for documentation meant to track the latest version of a project. Its contents can change, however, and the file may later move or disappear. If the tutorial describes exact code, a commit URL is more reproducible: obtain the commit ID for the revision you discuss, navigate to that revision on GitHub, and copy the file-view and raw links from there.
For a line-specific citation, select the relevant lines in the GitHub file view and copy the resulting URL. Check that the URL includes the intended commit rather than a changing branch if the line numbers must remain meaningful. A pinned commit identifies the revision; it does not guarantee that the repository will remain available or accessible indefinitely.
Advertisement
Check your links before publication
-
Open the file view. Confirm that the repository, revision, path, and any highlighted lines match the tutorial. If the file moved, update the link and check whether the surrounding explanation still applies.
-
Open the raw link. Confirm that it contains the intended file, not a login page, an error page, or another resource. For a download workflow, check the saved content as well as the HTTP status.
-
Inspect redirects. Redirects can be useful after a repository move, but do not assume they will exist forever. This command follows up to five redirects and reports the final URL, HTTP status, and content type:
url='https://raw.githubusercontent.com/octocat/Hello-World/master/README' curl -sS -L --max-redirs 5 --max-time 20 -o /dev/null \ -w 'final_url=%{url_effective}\nstatus=%{http_code}\ncontent_type=%{content_type}\n' \ "$url"Replace the example URL with the one you are checking. This command inspects the final response, not the contents or every intermediate redirect. A successful
curlinvocation alone does not establish that the HTTP response is successful or that the file is correct. -
Recheck branch assumptions. Confirm that the branch still exists and that the file matches the version discussed. If consistency matters more than tracking updates, use a commit link.
-
Test access as the intended reader. Open public links in a signed-out or private browser session. For a private repository, verify access using an authorized account with the required permissions; a private link does not grant access to others. Do not put credentials or access tokens in tutorial URLs.
These checks are especially important after repository renames, file moves, permission changes, or tutorial updates. GitHub may present inaccessible or missing resources differently depending on the request, so investigate rather than assuming a particular error always identifies the cause.
Common Mistakes
- Using a blob URL in a download command: the saved result may be HTML rather than the requested source file.
- Using a raw URL as a line citation: readers lose GitHub’s file context and line navigation.
- Pinning a branch when the tutorial depends on exact lines: later edits can make the instructions inaccurate.
- Assuming a redirect proves long-term availability: verify the destination and update stale links when possible.
- Testing only while signed in: a link that works for the author may be inaccessible to readers.
Best Practices
Choose the file view for explanation and the raw file for content retrieval. Pin a commit when readers need to reproduce the exact example; use a branch when following current changes is intentional. For important links, check both the response and the file contents as part of your publication and maintenance workflow.
Conclusion
A GitHub blob URL and a raw URL serve different jobs: one presents a file in context, while the other requests its contents. Match the link to the task, then verify the revision, access, and final response before publishing.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.