Github permalink bookmarklet

Linking to a URL on github like

github.com/someaccount/somerepo/blob/master/somefile

is fragile because "master" moves around. It's much better to link to a specific version of the file like

github.com/someaccount/somerepo/blob/somehash/somefile

But, github makes it easy to arrive at the former and hard to transition to the latter. I wish they would make it easy, but until that happens here's a handy bookmarklet I crafted that:

  • Redirects you to the associated permalink page
  • Shrinks the commit hash to the standard 7 character abbreviation
  • Maintains any urls hashes (e.g., highlighted line numbers)

The bookmarklet: github permalink (drag to your bookmark bar)

Use on any "blob" page, such as https://github.com/rails/rails/blob/master/version.rb#L1-2