Skip to content

Instantly share code, notes, and snippets.

@briankip
Last active February 2, 2024 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briankip/c2fb1d40873fc644ed66 to your computer and use it in GitHub Desktop.
Save briankip/c2fb1d40873fc644ed66 to your computer and use it in GitHub Desktop.
Linking to lines or chunks of code on github.

So you want to link to a line or chunk of code this is how you do it.

  1. Go to the file you are talking about, if you are viewing a number of files click to view the specific file.
  2. To select one line go to the gutter (where the line numbers are) and click the number, it will highlight in yellow.
  3. For multiple lines select the starting line as above then select shift click the end line. It will highlight the entire chuck of code.
  4. The URL will have automatically changed if you noticed, but this is not the canonical URL as when commits continue and the line numbers shift do to addition of code, sooner or later the URL will be pointing to something completely different.
  5. To prevent this hit Y and you will get the permanent canonical URL to the commit.
  6. Now the address bar has the permanent link to that chunk/line of code.
@mahadihassanriyadh
Copy link

Thank you, this was really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment