How to search github for code


Borislav Hadzhiev

Last updated: Feb 7, 2021


Check out my new book

If you work with new services/projects/environments that change quickly, like for example AWS services, you could either read the docs, which are often too bulky and lack examples or try to google around to see if other people have solved the problem you're trying to solve.

The alternative would be to search on github to look for examples in any of the public repositories available.

When you select a repository and enter the search term in the search bar in the navigation, you're looking for matches specifically in this repository, however when you do it on the / route on you have access to millions of public repositories.

Examples: #

Search for the term s3.deleteBucket by filtering the language to typescript and click on Code or Commits or Issues, depending on what you're looking for:

s3.deleteBucket language:typescript

Search for the term s3.deleteObject by filtering by file extension .js:

s3.deleteObject extension:js

Important: use quotation marks for queries with whitespace (multi word queries). For example if you wanted to search for the term new CfnAuthorizer it has whitespace so you have to put it in quotes to get reliable results:

"new CfnAuthorizer"

Similarly the following query matches issues with the word "build" that have the label "bug fix":

build label:"bug fix"

To search the code in all of a user's / organization's repositories use the user or org qualifier. To search the code in a specific repository use the repo qualifier.

Match code from @bobbyhadz that has file extension ts

user:bobbyhadz extension:ts

Match code from GitHub that ends in js

org:github extension:js

Match code from @bobbyhadz's config repository that ends in .md

repo:bobbyhadz/config extension:md

Match files named codebuild.yml with the word pre_build

filename:codebuild.yml pre_build

Exclude keywords when filtering, i.e. look for files with the word pre_build that don't have the word post_build

pre_build NOT post_build

Match commits authored by the user @bobbyhadz:


Match issues assigned to the person viewing the results:

is:issue assignee:@me
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.