Github Code Search

How to use Github's fuzzy-search for your repositories

Searching through code on Github

Github has just released the first preview version of its new search engine to look up code in your repositories. It’s called “Github Code Search” and provides a fuzzy-like search experience for your content on Github repositories. It crawls the repos and returns results that show the matching code lines.

As I noted, the service is currently in preview. I’m lucky to be one of the testers, but at the time of reading this article, Github Code Search might already be available to the general public.

Finding code among repos

The most basic yet also most powerful feature of Github Code Search is that you can just provide a query string and the engine will show you the relevant matches among all public repositories. Yes, you’ve read that correctly: the search returns results from not only your repositories, but all public ones by default.

Image c0a3654b99cb

All you have to do is enter the search parameter and hit enter on your keyboard. The next view will render all matches.

Image a313567091ec

Image 8e029df2d41c

Of course, you can limit the search to only inspect your account’s content. This can either be done by using the prefix “owner:” to your query or by selecting your account from the left dropdown button in the search bar.

Image bced85f2510f

If you define the scope via the dropdown button to your account, the results get also rendered inline as a list, which is really nice for doing quick searches without changing the page.

Image 594c02a08392

Image fdce76da6bf1

Github’s custom query language

A more advanced feature of Github Code Search is the ability to precisely define the scope of the search via regular expressions, file paths as well as boolean operators. All together they allow you to write queries in a simple but quite efficient language.

Image d760820b6ea3

As this is only the first iteration of the service, I’m sure Github Code Search will become much more powerful in the future. After using it for some time during the preview phase I can already say that it will be one of the most used features on Github.

I also think that Github Code Search can evolve into a competitor to Stack Overflow when it comes to searching for code snippets or templates - a feature that might already be covered by Github Copilot.