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.
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.
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.
LikeLike
Ah yes, good catch! I know I talk about this later in the series, but I should have included it here. Thanks again! 🙂
LikeLike