Search code
Searches for query terms inside of a file. This method returns up to 100 results [per page](https://docs.github.com/[email protected]/rest/overview/resources-in-the-rest-api#pagination). When searching for code, you can get text match metadata for the file **content** and file **path** fields when you pass the `text-match` media type. For more details about how to receive highlighted search results, see [Text match metadata](https://docs.github.com/[email protected]/rest/reference/search#text-match-metadata). For example, if you want to find the definition of the `addClass` function inside [jQuery](https://github.com/jquery/jquery) repository, your query would look something like this: `q=addClass+in:file+language:js+repo:jquery/jquery` This query searches for the keyword `addClass` within a file's contents. The query limits the search to files where the language is JavaScript in the `jquery/jquery` repository. #### 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. * You must always include at least one search term when searching source code. For example, searching for [`language:go`](https://github.com/search?utf8=%E2%9C%93&q=language%3Ago&type=Code) is not valid, while [`amazing language:go`](https://github.com/search?utf8=%E2%9C%93&q=amazing+language%3Ago&type=Code) is.
/search/code- Source
github-v3-rest.json- Revision
f5f067c1e6f6- Active snapshot
85e53e3d0d65
Request
Query Parameters
- q stringrequired
The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see [Constructing a search query](https://docs.github.com/[email protected]/rest/reference/search#constructing-a-search-query). See "[Searching code](https://docs.github.com/articles/searching-code/)" for a detailed list of qualifiers.
- sort stringoptional
Sorts the results of your query. Can only be `indexed`, which indicates how recently a file has been indexed by the GitHub Enterprise Server search infrastructure. Default: [best match](https://docs.github.com/[email protected]/rest/reference/search#ranking-search-results)
- order stringoptional
Determines whether the first search result returned is the highest number of matches (`desc`) or lowest number of matches (`asc`). This parameter is ignored unless you provide `sort`.
- per_page integeroptional
Results per page (max 100)
- page integeroptional
Page number of the results to fetch.
Responses
Response
items array[Code Search Result Item object]required
items Code Search Result Item objectCode Search Result Item
Code Search Result Item
[
"73..77",
"77..78"
] repository Minimal Repository objectrequiredMinimal Repository
Minimal Repository
Example: http://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}
Example: http://api.github.com/repos/octocat/Hello-World/assignees{/user}
Example: http://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}
Example: http://api.github.com/repos/octocat/Hello-World/branches{/branch}
Code Of Conduct
Example: http://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}
Example: http://api.github.com/repos/octocat/Hello-World/comments{/number}
Example: http://api.github.com/repos/octocat/Hello-World/commits{/sha}
Example: http://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}
Example: http://api.github.com/repos/octocat/Hello-World/contents/{+path}
Example: http://api.github.com/repos/octocat/Hello-World/contributors
Example: 2011-01-26T19:01:12Z
Example: http://api.github.com/repos/octocat/Hello-World/deployments
Example: This your first repo!
Example: http://api.github.com/repos/octocat/Hello-World/downloads
Example: http://api.github.com/repos/octocat/Hello-World/events
Example: 0
Example: http://api.github.com/repos/octocat/Hello-World/forks
Example: octocat/Hello-World
Example: http://api.github.com/repos/octocat/Hello-World/git/commits{/sha}
Example: http://api.github.com/repos/octocat/Hello-World/git/refs{/sha}
Example: http://api.github.com/repos/octocat/Hello-World/git/tags{/sha}
Example: http://api.github.com/repos/octocat/Hello-World/hooks
Example: https://github.com/octocat/Hello-World
Example: 1296269
Example: http://api.github.com/repos/octocat/Hello-World/issues/comments{/number}
Example: http://api.github.com/repos/octocat/Hello-World/issues/events{/number}
Example: http://api.github.com/repos/octocat/Hello-World/issues{/number}
Example: http://api.github.com/repos/octocat/Hello-World/keys{/key_id}
Example: http://api.github.com/repos/octocat/Hello-World/labels{/name}
Example: http://api.github.com/repos/octocat/Hello-World/languages
Example: http://api.github.com/repos/octocat/Hello-World/merges
Example: http://api.github.com/repos/octocat/Hello-World/milestones{/number}
Example: Hello-World
Example: MDEwOlJlcG9zaXRvcnkxMjk2MjY5
Example: http://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}
Example: 0
Simple User
Example: http://api.github.com/repos/octocat/Hello-World/pulls{/number}
Example: 2011-01-26T19:06:43Z
Example: http://api.github.com/repos/octocat/Hello-World/releases{/id}
Example: http://api.github.com/repos/octocat/Hello-World/stargazers
Example: http://api.github.com/repos/octocat/Hello-World/statuses/{sha}
Example: http://api.github.com/repos/octocat/Hello-World/subscribers
Example: http://api.github.com/repos/octocat/Hello-World/subscription
Example: http://api.github.com/repos/octocat/Hello-World/tags
Example: http://api.github.com/repos/octocat/Hello-World/teams
A git repository
Example: http://api.github.com/repos/octocat/Hello-World/git/trees{/sha}
Example: 2011-01-26T19:14:43Z
Example: https://api.github.com/repos/octocat/Hello-World
Example: 0
Not modified
Forbidden
Validation failed
errors array[object]optional
items object
Service unavailable