When including a reference to some line(s) of code in a GitHub repository, please do this by using the canonical form of the URL. You can do this by pressing y when browsing a single file on GitHub. This will replace the “pretty” URL with a version that includes the exact commit of the file you are looking at, and this will work for the most recent version of a file, but also when browsing some branch or tag.

For example, the URL https://github.com/tfrommen/Dobby/blob/master/dobby.php#L49-L55, pointing to the action hook to use for Dobby, right now, would turn into https://github.com/tfrommen/Dobby/blob/bd05c174c876c9b69d5a2abc7f59eb2606911d57/dobby.php#L49-L55.

Why? Well, when you include a “pretty” GitHub URL to some piece of code somewhere more persistant—in a blog post, a ticket, documentation etc.—it may soon be the case that your link no longer points to what you want. This is especially true if you linked to some place way down in a looong, long file, but it’s true in general.

Canonical URLs will always work, and they will always point to the exact same things you referenced, no matter when you look at them. And in case you can’t remember the shortcut, GitHub recently added a UI for this:

Leave a Reply

Your email address will not be published. Required fields are marked *