How to link directly to a line of code in a file hosted on GitHub – 043

It’s a lot easier to point someone directly to a line of code you’re referring to, rather than sending them the link to a file with a message “and now scroll to line 74.”

First, you’ll navigate to a file hosted on GitHub. It could be a file you’ve checked in or any random file in any random repo.

Next, click on the line number that you want to get a link to. In today’s example, you’ll see me refer to one of my sample Electron apps where I forgot to remove the line that shows developer tools for debugging.

Clicking line number in a file on GitHub.com

And volia, check your web browser address bar. You now have a URL for that exact line of code, e.g.  https://github.com/saraford/your-moment-of-github-zen/blob/master/main.js#L74

When you send this link to someone else, the line of code will open around the middle of the screen with the yellow highlight.

2 thoughts on “How to link directly to a line of code in a file hosted on GitHub – 043

  1. Great tip.

    For extra points pay attention to the /blob/master/ part of the URL.

    Replace master with the name of any branch to link to the version of code on that branch.

    Of course, branches move over time, so to ensure that the link remains valid (or at least add a reasonable degree of future-proofing) replace the branch name with the name of a tag or even the significant digits of a commit SHA.

    Like

Leave a comment