To search for code, use the following search qualifiers in any combination.

Tips:

  • This article contains example searches on the GitHub.com website, but you can use the same search filters on your GitHub Enterprise instance.
  • There's a list of search syntaxes you can add to any search qualifier to further improve your results.

Considerations for code search

Due to the complexity of searching code, there are a few restrictions on how searches are performed:

  • Only the default branch is considered. In most cases, this will be the master branch.
  • Only files smaller than 384 KB are searchable.
  • Only repositories with fewer than 500,000 files are searchable.
  • You must always include at least one search term when searching source code. For example, searching for language:go is not valid, while amazing language:go is.
  • At most, search results can show two fragments from the same file, but there may be more results within the file.
  • You can't use the following wildcard characters as part of your search query: . , : ; / \ ` ' " = * ! ? # $ & + ^ | ~ < > ( ) { } [ ]. The search will simply ignore these symbols.

Scope the search fields

The in qualifier limits what fields are searched. With this qualifier, you can restrict your search to the source code, the file path, or both. Without the qualifier, only the file contents are searched.

octocat in:file
Matches code where "octocat" appears in the file contents.
octocat in:path
Matches code where "octocat" appears in the path name.
octocat in:file,path
Matches code where "octocat" appears in the file contents or the path name.
display language:scss
Matches code with the word "display," that's marked as being SCSS.
Integer
Matches code with the word "Integer".

Search by language

You can search for code based on what language it's written in. For example:

element language:xml size:100
Matches code with the word "element" that's marked as being XML and has exactly 100 bytes.
user:mozilla language:markdown
Matches code from all @mozilla's repositories that's marked as Markdown.

Search by the number of forks the parent repository has

Much like with repositories, you can opt to search code files that exist within forked repositories. However, to ensure better relevancy, repository forks will not be searchable unless the fork has more stars than the parent repository.

If you would like forked results to appear, add the fork:true qualifier. For example:

android language:java fork:true
Matches code in a forked repository with the word "android" that's written in Java.

Search by the size of the parent repository

The size qualifier filters results based on the size of the file in which the code is found. For example:

function size:>10000 language:python
Matches code with the word "function," written in Python, in files that are larger than 10 KB.

Search by the location of a file within the repository

By including the path qualifier, you specify that resulting source code must appear at a specific location in a repository. Subfolders are considered during the search, so be as specific as possible. For example:

console path:app/public language:javascript
Finds JavaScript files with the word "console" in an app/public directory (even if they reside in app/public/js/form-validators).
form path:cgi-bin language:perl
Finds Perl files under cgi-bin with the word "form" in them.

Search by filename

You can use the filename qualifier if there's a specific file you're looking for. For example:

filename:.vimrc commands
Finds *.vimrc* files with the word "commands" in them.
minitest filename:test_helper path:test language:ruby
Finds Ruby files containing the word "minitest" named *test_helper* within the *test* directory.

Search by the file extension

The extension qualifier matches code files with a certain extension. For example:

form path:cgi-bin extension:pm
Matches code with the word "form," under cgi-bin, with the .pm extension.
icon size:>200000 extension:css
Finds files larger than 200 KB that end in .css and have the word "icon" in them.

Search within a user's or organization's repositories

To grab a list of code from all repositories owned by a certain user or organization, you can use the user syntax. For getting a list of code from a specific repository, you can use the repo syntax. For example:

user:github extension:rb
Matches code from GitHub that ends in .rb.
repo:mozilla/shumway extension:as
Matches code from @mozilla's shumway project that ends in .as.

Sort the results

With any of the qualifiers above, you can also choose to sort on when the code was last indexed. This can be in ascending or descending order.