GitHub rolled out embedded code snippets this month which should make it easier to share existing code without having to re-create it in a comment.
For a while, GitHub has had the ability to highlight lines with a URL hash. For example, if you want to highlight lines 10-15, you would append
#L10-L15 to the URL.
Now when you highlight lines, GitHub provides a menu allowing you to copy the selected lines, copy the permalink, and open a new issue which contains the embedded code.
Another neat trick I discovered while learning about this new feature is the ability to highlight a line while looking at a file on GitHub.com, then using
Shift+Click to highlight a selection of the original line and the last line clicked. You can highlight a line by clicking the line number in the gutter of the file. If you keep holding shift and clicking line numbers below the original, the UI will further highlight lines.
I’ve shared highlighted lines manually for some time now, and it has always been a pain to copy the code and paste it in a pull request or issue. Embedded code snippets are a great productivity improvement for me, as I spend a good chunk of time reviewing others’ code and working through internal issues and bugs.
Another benefit of embedded snippets is they link back to the original file and show a nicely formatted code block with contexts such as line numbers and file name, so you know which file is being shared without any explanation on your part.
You can learn more about embedded code snippets on the official GitHub blog post Introducing Embedded Code Snippets.
Join the weekly newsletter and never miss out on new tips, tutorials, and more.
- Software Engineer Lead (PHP)
- Full-time Senior Web Developer
Wayne State University
- Senior Software Engineer
- Full Stack Engineer
Remote or Medford, Oregon
- Laravel Developer (fulltime - Dutch only)
Qbixx | Webservices
- Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
- Senior Quality Assurance Engineer
Quickly Edit Your Theme Colors and Fonts in PhpStorm
PhpStorm has released a new feature that allows you to quickly find and edit the theme style for a given line you wan…
New Laravel String Helpers in 5.4 and 5.5
New string helpers are finding their way into Laravel leading up to the big 5.5 release, which is planned to drop dur…