Let's say I'm on a GitHub page for a file in a repository, like so:


Note that this links to line 33 and branch master. If I want to reference this is in an issue or pull request, I'd want a link to the current commit, so that updates to the file don't invalidate my link.

Is there a one-click way to do this?

Obviously, I can click on the commit at the top, copy the SHA, and paste it over master, but that's inconvenient.

  • Hopefully you've figured out a way to do it by now, but if not a simple bookmarklet would allow you to get the correct link to the commit and copy it to the clipboard with just one click and a CTRL + C. You just want to copy the URL to that commit?
    – freginold
    Apr 4, 2017 at 14:26

1 Answer 1


Here's a bookmarklet that can grab the commit URL for you. Just copy the code below into a bookmark in your browser, then when you're viewing a page like the one you linked to above, click the bookmark. A box will appear at the bottom of the screen like this one, containing the URL for the commit page:

URL copy box

Press CTRLC to copy the link (which will already be highlighted) and from there you can paste it wherever you need it.

Make sure that when you copy the code into a bookmark that javascript: appears at the beginning. (In some browsers, it doesn't always copy over.)

(function() {
  var commitLink = document.getElementsByClassName("message")[0].href;
  var linkModal = document.createElement('input');
  linkModal.type = "text";
  linkModal.innerText = commitLink;
  linkModal.contentEditable = false;
  linkModal.size = commitLink.length * 1.1;
  linkModal.style.zIndex = 10000;
  linkModal.style.border = "2px solid red";
  linkModal.style.borderRadius = "4px";
  linkModal.style.fontFamily = "sans-serif";
  linkModal.style.fontSize = "1em";
  linkModal.style.backgroundColor = "white";
  linkModal.style.color = "black";
  linkModal.style.padding = "3px 7px 4px 7px";
  linkModal.style.position = "fixed";
  linkModal.style.left = "37%";
  linkModal.style.bottom = "0%";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.