2023-2025+: https://github.com/search?type=Code

Example inside a project: https://github.com/search?q=repo%3Agit%2Fgit+rebase&type=code

Update May 2023:

The new code search and code view is now generally available (May. 2023)

(As noted by holydragon in the comments, that does require to sign in to GitHub first)

At GitHub Universe last year, we announced a total redesign of GitHub's code search and navigation experience, powered by our all-new code search engine that we built from scratch.
And in February, we announced our public beta.

Today, we are rolling out this feature to all GitHub users.

Check out our blog post to learn more about how GitHub's new code search and code view can help you search, navigate, and understand your code.
And if you have feedback, please share it with us in our feedback discussion.


Update Dec. 2021: search has been improved again, with Search for an exact string, with support for substring matches and special characters, or regexps.

But only on cs.github.com, and still in beta (waitlist applies)


Update January 2013: a brand new search has arrived!, based on elasticsearch.org:

A search for stat within the ruby repo will be expressed as stat repo:ruby/ruby, and will now just workTM.
(the repo name is not case sensitive: test repo:wordpress/wordpress returns the same as test repo:Wordpress/Wordpress)

Will give:

And you have many other examples of search, based on followers, or on forks, or...


Update July 2012 (old days of Lucene search and poor code indexing, combined with broken GUI, kept here for archive):

The search (based on SolrQuerySyntax) is now more permissive and the dreaded "Invalid search query. Try quoting it." is gone when using the default search selector "Everything":)

(I suppose we can all than Tim Pease, which had in one of his objectives "hacking on improved search experiences for all GitHub properties", and I did mention this Stack Overflow question at the time ;) )

Here is an illustration of a grep within the ruby code: it will looks for repos and users, but also for what I wanted to search in the first place: the code!


Initial answer and illustration of the former issue (Sept. 2012 => March 2012)

You can use the advanced search GitHub form:

  • Choose Code, Repositories or Users from the drop-down and
  • use the corresponding prefixes listed for that search type.

For instance, Use the repo:username/repo-name directive to limit the search to a code repository.
The initial "Advanced Search" page includes the section:

Code Search:

The Code search will look through all of the code publicly hosted on GitHub. You can also filter by :

  • the language language:
  • the repository name (including the username) repo:
  • the file path path:

So if you select the "Code" search selector, then your query grepping for a text within a repo will work:


What is incredibly unhelpful from GitHub is that:

  • if you forget to put the right search selector (here "Code"), you will get an error message:
    "Invalid search query. Try quoting it."

  • the error message doesn't help you at all.
    No amount of "quoting it" will get you out of this error.

  • once you get that error message, you don't get the sections reminding you of the right association between the search selectors ("Repositories", "Users" or "Language") and the (right) search filters (here "repo:").
    Any further attempt you do won't display those associations (selectors-filters) back. Only the error message you see above...
    The only way to get back those arrays is by clicking the "Advance Search" icon:

  • the "Everything" search selector, which is the default, is actually the wrong one for all of the search filters! Except "language:"...
    (You could imagine/assume that "Everything" would help you to pick whatever search selector actually works with the search filter "repo:", but nope. That would be too easy)

  • you cannot specify the search selector you want through the "Advance Search" field alone!
    (but you can for "language:", even though "Search Language" is another combo box just below the "Search for" 'type' one...)


So, the user's experience usually is as follows:

  • you click "Advanced Search", glance over those sections of filters, and notice one you want to use: "repo:"
  • you make a first advanced search "repo:jruby/jruby stat", but with the default Search selector "Everything"
    => FAIL! (and the arrays displaying the association "Selectors-Filters" is gone)
  • you notice that "Search for" selector thingy, select the first choice "Repositories" ("Dah! I want to search within repositories...")
    => FAIL!
  • dejected, you select the next choice of selectors (here, "Users"), without even looking at said selector, just to give it one more try...
    => FAIL!
  • "Screw this, GitHub search is broken! I'm outta here!"
    ...
    (GitHub advanced search is actually not broken. Only their GUI is...)

So, to recap, if you want to "grep for something inside a Github project's code", as the OP Ben Humphreys, don't forget to select the "Code" search selector...

Answer from VonC on Stack Overflow
Top answer
1 of 12
326

2023-2025+: https://github.com/search?type=Code

Example inside a project: https://github.com/search?q=repo%3Agit%2Fgit+rebase&type=code

Update May 2023:

The new code search and code view is now generally available (May. 2023)

(As noted by holydragon in the comments, that does require to sign in to GitHub first)

At GitHub Universe last year, we announced a total redesign of GitHub's code search and navigation experience, powered by our all-new code search engine that we built from scratch.
And in February, we announced our public beta.

Today, we are rolling out this feature to all GitHub users.

Check out our blog post to learn more about how GitHub's new code search and code view can help you search, navigate, and understand your code.
And if you have feedback, please share it with us in our feedback discussion.


Update Dec. 2021: search has been improved again, with Search for an exact string, with support for substring matches and special characters, or regexps.

But only on cs.github.com, and still in beta (waitlist applies)


Update January 2013: a brand new search has arrived!, based on elasticsearch.org:

A search for stat within the ruby repo will be expressed as stat repo:ruby/ruby, and will now just workTM.
(the repo name is not case sensitive: test repo:wordpress/wordpress returns the same as test repo:Wordpress/Wordpress)

Will give:

And you have many other examples of search, based on followers, or on forks, or...


Update July 2012 (old days of Lucene search and poor code indexing, combined with broken GUI, kept here for archive):

The search (based on SolrQuerySyntax) is now more permissive and the dreaded "Invalid search query. Try quoting it." is gone when using the default search selector "Everything":)

(I suppose we can all than Tim Pease, which had in one of his objectives "hacking on improved search experiences for all GitHub properties", and I did mention this Stack Overflow question at the time ;) )

Here is an illustration of a grep within the ruby code: it will looks for repos and users, but also for what I wanted to search in the first place: the code!


Initial answer and illustration of the former issue (Sept. 2012 => March 2012)

You can use the advanced search GitHub form:

  • Choose Code, Repositories or Users from the drop-down and
  • use the corresponding prefixes listed for that search type.

For instance, Use the repo:username/repo-name directive to limit the search to a code repository.
The initial "Advanced Search" page includes the section:

Code Search:

The Code search will look through all of the code publicly hosted on GitHub. You can also filter by :

  • the language language:
  • the repository name (including the username) repo:
  • the file path path:

So if you select the "Code" search selector, then your query grepping for a text within a repo will work:


What is incredibly unhelpful from GitHub is that:

  • if you forget to put the right search selector (here "Code"), you will get an error message:
    "Invalid search query. Try quoting it."

  • the error message doesn't help you at all.
    No amount of "quoting it" will get you out of this error.

  • once you get that error message, you don't get the sections reminding you of the right association between the search selectors ("Repositories", "Users" or "Language") and the (right) search filters (here "repo:").
    Any further attempt you do won't display those associations (selectors-filters) back. Only the error message you see above...
    The only way to get back those arrays is by clicking the "Advance Search" icon:

  • the "Everything" search selector, which is the default, is actually the wrong one for all of the search filters! Except "language:"...
    (You could imagine/assume that "Everything" would help you to pick whatever search selector actually works with the search filter "repo:", but nope. That would be too easy)

  • you cannot specify the search selector you want through the "Advance Search" field alone!
    (but you can for "language:", even though "Search Language" is another combo box just below the "Search for" 'type' one...)


So, the user's experience usually is as follows:

  • you click "Advanced Search", glance over those sections of filters, and notice one you want to use: "repo:"
  • you make a first advanced search "repo:jruby/jruby stat", but with the default Search selector "Everything"
    => FAIL! (and the arrays displaying the association "Selectors-Filters" is gone)
  • you notice that "Search for" selector thingy, select the first choice "Repositories" ("Dah! I want to search within repositories...")
    => FAIL!
  • dejected, you select the next choice of selectors (here, "Users"), without even looking at said selector, just to give it one more try...
    => FAIL!
  • "Screw this, GitHub search is broken! I'm outta here!"
    ...
    (GitHub advanced search is actually not broken. Only their GUI is...)

So, to recap, if you want to "grep for something inside a Github project's code", as the OP Ben Humphreys, don't forget to select the "Code" search selector...

2 of 12
89

To seach within a repository, add the URL parametes /search?q=search_terms at the root of the repo, for example:

https://github.com/bmewburn/vscode-intelephense/search?q=phpstorm

In the above example, it returns 2 results in Code and 160 results in Issues.

🌐
GitHub
github.com › features › code-search
GitHub Code Search · GitHub
Dig deeper with the all-new code view—tightly integrating browsing and code navigation. GitHub code search can search across multiple repositories and is always up to date.
Discussions

Code Search API for multiple-repo queries
Is there an API for the code search that supports searching across multiple of my own repositories? I have found docs about search, but it seems to only work in a single repository and not be related to the newest version of search that's much more useful · Beta Was this translation helpful? Give feedback. ... Yes, GitHub ... More on github.com
🌐 github.com
3
3
Reddit - The heart of the internet
Reddit is where millions of people gather for conversations about the things they care about, in over 100,000 subreddit communities. More on reddit.com
🌐 reddit.com
12 hours ago
How to search things in github repository?
You can press . in any GitHub repository to open it in an online version of VSCode. That should make searching in your project very easy. More on reddit.com
🌐 r/github
8
14
December 27, 2021
Search for keyword in file
Can I find a file containing a keyword in GitHub or should I clone the repo and use grep? Thank you More on reddit.com
🌐 r/github
2
2
January 26, 2022
🌐
GitHub
docs.github.com › en › repositories › working-with-files › using-files › navigating-code-on-github
Navigating code on GitHub - GitHub Docs
Symbol search is a feature of code search. For more information, see Understanding GitHub Code Search syntax. Select a repository, then navigate to a file containing symbols.
🌐
Grep
grep.app
Code Search | Grep by Vercel
Effortlessly search for code, files, and paths across a million GitHub repositories.
🌐
GitHub
github.com › orgs › community › discussions › 60088
Search within code of repositories · community · Discussion #60088
You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... It's currently not possible to search within the code of a repository on mobile (at least iOS).
🌐
GitHub
cli.github.com › manual › gh_search_code
gh search code
# Search code matching "react" and "lifecycle" $ gh search code react lifecycle # Search code matching "error handling" $ gh search code "error handling" # Search code using raw search qualifiers as separate arguments $ gh search code panic path:pkg language:go # Search code matching "deque" in Python files $ gh search code deque --language=python # Search code matching "cli" in repositories owned by microsoft organization $ gh search code cli --owner=microsoft # Search code matching "panic" in the GitHub CLI repository $ gh search code panic --repo cli/cli # Search code matching keyword "lint" in package.json files $ gh search code lint --filename package.json
Find elsewhere
🌐
GitHub
docs.github.com › en › search-github › searching-on-github › searching-code
Searching code (legacy) - GitHub Docs
August 24, 2021 - Code in forks is only searchable if the fork has more stars than the parent repository, and the forked repository has at least one pushed commit after being created. Forks with fewer stars than the parent repository or no commits are not indexed for code search.
🌐
GitHub
github.com › github › docs › blob › main › content › search-github › searching-on-github › searching-code.md
docs/content/search-github/searching-on-github/searching-code.md at main · github/docs
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.
Author   github
🌐
Flaming Codes
flaming.codes › posts › github code search to quickly find code in all repositories
Github Code Search to quickly find code in all repositories
January 11, 2022 - 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.
🌐
GitHub
github.com › github › docs › blob › main › content › search-github › github-code-search › understanding-github-code-search-syntax.md
docs/content/search-github/github-code-search/understanding-github-code-search-syntax.md at main · github/docs
For example: ... To search within a set of repositories, you can combine multiple repo: qualifiers with the boolean operator OR. For example: repo:github-linguist/linguist OR repo:tree-sitter/tree-sitter ...
Author   github
🌐
GitHub
docs.github.com › en › search-github › getting-started-with-searching-on-github › about-searching-on-github
About searching on GitHub - GitHub Docs
March 15, 2022 - GitHub Pages sites are not searchable on GitHub. However, you can search the source content if it exists in the default branch of a repository, using code search. For more information, see Understanding GitHub Code Search syntax.
🌐
freeCodeCamp
freecodecamp.org › news › github-search-tips
GitHub Search Tips – How to Search Issues, Repos, and More Effectively on GitHub
October 17, 2022 - Another cool way to search through GitHub is by language. This helps you filter out repositories to a specific language. ... Using language:LANGUAGE. For example if you want to find repositories written in PHP, your search will be: language:PHP
🌐
Trupeer
trupeer.ai › home › tutorials › how to search code in github
How to Search Code in Github | Trupeer AI Tutorial Video Maker
Log in to Your GitHub Account Visit github.com and sign in using your GitHub credentials. Use the Search Bar at the Top In the top-left corner of the page, click the search bar and type the code, function name, or keyword you want to find.
🌐
GitHub
github.com › orgs › community › discussions › 77468
Ability to search based on repository topic or property? · community · Discussion #77468
November 30, 2023 - However you cannot search for code that lives within repos that have a topic. You'll get the warning message The topic qualifier is not supported when searching code. Try searching for repositories instead?
🌐
Wordpress
nataliekarolak.wordpress.com › 2025 › 07 › 01 › search-code-on-github-in-the-browser
Search code on GitHub in the browser – The BC Docs Librarian
July 2, 2025 - Whereas the GitHub code search supports the default branch only, the github.dev editor enables you to use native VS Code search tools on any branch you like. Let’s try it out for the MSDyn365BC.Code.History repository!
🌐
GitHub
github.blog › home › news & insights › the library › github code search
GitHub Code Search - The GitHub Blog
January 4, 2019 - GitHub Codesearch can be found at github.com/codesearch and will let you type in anything you’re looking for in source code and get highlighted results of any files in our public repositories that match.
🌐
GitHub
github.com › cli › cli › discussions › 2913
Searching or Querying through GitHub Repositories and its file content · cli/cli · Discussion #2913
$ gh api -X GET search/code -f q='TODO repo:cli/cli' -F per_page=100 | jq -r '.items[].html_url' This finds files with the word "TODO" in the cli/cli repository and prints their web URLs.
Author   cli