I am not the type of person who remembers shortcuts/hotkeys. Only few valuable ones stick. Those that pass the test of time.
Before I share a GitHub link pointing to code I press y
. This might be one of the most important hotkeys of my day-to-day work. And I would love to see more of you people out there doing that, too!
It makes the URL in the location bar point to the specific revision of the code you are looking at, as opposed to the head of the current branch (which often is main
).
You have two options:
- Select the line of code, press y, copy the URL, share it (for example in a GitHub comment). In the future, that URL will either stop working or point to the file, line or code section you actually wanted to refer to. Either this or that. No room for misleading moving target effects (well, malicious intent excluded, but even that is hopefully close to impossible). It is quite likely that even after years the comment, prose, article or chat log in which you used that URL is still going to be perfectly meaningful. How cool is that?
- Select the line of code, copy the URL, share it. Lucky you, you have just saved yourself some work (did not press
y
). But: The URL you have just shared is quite likely to point to a moving target. In a busy project in a busy file, it might only take a day and it will not refer to quite the right thing anymore. On longer time scales it gets worse. Once you put this into a public GitHub comment, email, forum post or chat then your content might first start to look subtly wrong, and then very wrong in the far future. Especially in the spectrum in between not all future readers might realize what actually happened. That can be quite misleading.
Choose for yourself :-).
Given the role into which GitHub has evolved for how we do software engineering these days, I think it is pretty important to spread this. Tell your peeps!
Reference: Getting permanent links to files in the GitHub docs.
Leave a Reply