You can search globally across all of GitHub Enterprise Server, or scope your search to a particular repository or organization. For more information, see "About searching on GitHub."
You can only search code using these code search qualifiers. Search qualifiers specifically for repositories, users, or commits, will not work when searching for code.
Tips:
- This article contains links to example searches on the GitHub.com website, but you can use the same search filters with GitHub Enterprise Server. In the linked example searches, replace
github.comwith the hostname for your GitHub Enterprise Server instance. - For a list of search syntaxes that you can add to any search qualifier to further improve your results, see "Understanding the search syntax".
- Use quotations around multi-word search terms. For example, if you want to search for issues with the label "In progress," you'd search for
label:"in progress". Search is not case sensitive.
Considerations for code search
Due to the complexity of searching code, there are some restrictions on how searches are performed:
- You must be signed into a personal account on GitHub Enterprise Server to search for code across all public repositories.
- Code in forks is only searchable if the fork has more stars than the parent repository. Forks with fewer stars than the parent repository are not indexed for code search. To include forks with more stars than their parent in the search results, you will need to add
fork:trueorfork:onlyto your query. For more information, see "Searching in forks." - Only the default branch is indexed for code search.* Only files smaller than 5 MB are searchable.
- Only the first 500 KB of each file is searchable.
- Up to 4,000 private and internal repositories are searchable. These 4,000 repositories will be the most recently updated of the first 10,000 private and internal repositories that you have access to.
- Only repositories with fewer than 500,000 files are searchable.
- Except with
filenamesearches, you must always include at least one search term when searching source code. For example, searching forlanguage:javascriptis not valid, whileamazing language:javascriptis. - 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.
Search by the file contents or file path
With the in qualifier you can restrict your search to the contents of the source code file, the file path, or both. When you omit this qualifier, only the file contents are searched.
| Qualifier | Example |
|---|---|
in:file | octocat in:file matches code where "octocat" appears in the file contents. |
in:path | octocat in:path matches code where "octocat" appears in the file path. |
in:file,path | octocat in:file,path matches code where "octocat" appears in the file contents or the file path. |
Search within a user's or organization's repositories
To search the code in all repositories owned by a certain user or organization, you can use the user or org qualifier. To search the code in a specific repository, you can use the repo qualifier.
| Qualifier | Example |
|---|---|
user:USERNAME | user:defunkt extension:rb matches code from @defunkt that ends in .rb. |
org:ORGNAME | org:github extension:js matches code from GitHub that ends in .js. |
repo:USERNAME/REPOSITORY | repo:mozilla/shumway extension:as matches code from @mozilla's shumway project that ends in .as. |
Search by file location
You can use the path qualifier to search for source code that appears at a specific location in a repository. Use path:/ to search for files that are located at the root level of a repository. Or specify a directory name or the path to a directory to search for files that are located within that directory or any of its subdirectories.
| Qualifier | Example |
|---|---|
path:/ | octocat filename:readme path:/ matches readme files with the word "octocat" that are located at the root level of a repository. |
path:DIRECTORY | form path:cgi-bin language:perl matches Perl files with the word "form" in the cgi-bin directory, or in any of its subdirectories. |
path:PATH/TO/DIRECTORY |