Sharing GitHub commit hashes directly works for ephemeral uses, but there is a safer way for links that need to last.
By default, when you click through a repository on the GitHub website, you're browsing the default branch. This is often useful, as you may want the latest version of each file.
(Notice below the
blob/main segments — here
main is the default branch.)
While this may be great when browsing, it's problematic when sharing the URL for a few reasons:
To overcome this issue, you can use commit hashes when sharing the URL. The easiest way to do this when looking at a file on the default branch is to replace the default branch in the URL with the latest commit for that particular file.
Fortunately, you can grab this while viewing the file, as the latest relevant commit for that file is listed on the page.
Alternatively, you can use the Browse Files button (after clicking the commit hash link) to browse the entire project at that hash.
You can do this from any commit screen. And generally, whenever a commit is shown in the GitHub app, it is a link leading to the commit detail view (shown above).