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.

🌐
Latenode
community.latenode.com › other questions › github
How to find specific text within GitHub repository files - Github - Latenode Official Community
July 16, 2025 - I’m trying to locate particular strings or patterns within the source code of a GitHub repository. While I know I can clone the entire repo to my machine and use local search tools, I’m curious if there are built-in feat…
Discussions

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
Why doesn't github search return the file that contains my search string? (Newbie)
https://docs.github.com/en/search-github/searching-on-github/searching-code#considerations-for-code-search has the answer: Only files smaller than 384 KB are searchable. https://github.com/emacs-mirror/emacs/blob/master/lisp/org/org.el is 815KB More on reddit.com
🌐 r/github
10
12
March 4, 2022
git - How to: find string in GitHub repo? - Stack Overflow
I know where it is from the frontend, ... repo for a string. ... No, I mean on the GitHub project page. ... Save this answer. ... Show activity on this post. You can search an entire repo in github by using the search bar found at the top left corner of the screen. ... Sign up to request clarification or add additional context in comments. ... That doesn't search only strings. That searchers everything, including code, comments, and text ... More on stackoverflow.com
🌐 stackoverflow.com
Show HN: Search code in GitHub repos using regular expressions
I'm the CTO @ GitHub. Would love to talk to you about this and other things we are building in this area at GitHub · Feel free to email direct to jason at github.com More on news.ycombinator.com
🌐 news.ycombinator.com
155
614
February 25, 2020
🌐
Reddit
reddit.com › r/github › search for keyword in file
r/github on Reddit: Search for keyword in file
January 26, 2022 - The search function on GitHub is pretty good I’ve found. You can directly search by keyword in a repo and it will pull location of the file as a clickable link to that file.
🌐
DEV Community
dev.to › dougblackjr › find-a-string-in-a-massive-git-repo-22h9
Find A String in a Massive Git Repo - DEV Community
May 8, 2019 - :) ... You might want to check out the options on the git log command as well, as it can be used to search across all history rather than just all current branches. For example to search all commit messages for the string "foo bar baz":
🌐
GitHub
docs.github.com › en › github › searching-for-information-on-github › getting-started-with-searching-on-github › about-searching-on-github
About searching on GitHub - GitHub Docs
July 24, 2020 - You can search globally across all of GitHub, or scope your search to a particular repository or organization. To search globally across all of GitHub, type what you're looking for into the search field at the top of any page, and choose "Search all of GitHub" in the search dropdown menu.
🌐
Educative
educative.io › answers › how-to-search-in-a-git-repository
How to search in a Git repository
It will now search in all the git branches for the word “password” and display the console results. Searching in Git is powerful --you can search anywhere in your Git repo. In this shot, you have learned two ways to search in Git repo: with commit hash and with free text.
Find elsewhere
🌐
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'
Author   cli
🌐
freeCodeCamp
freecodecamp.org › news › github-search-tips
GitHub Search Tips – How to Search Issues, Repos, and More Effectively on GitHub
October 17, 2022 - If you want find repositories that have less than 100 forks, your search will be: forks:<100. The good thing is that you can always use relational operators like <, >, <=, >= & .. to help you further narrow your search. Another cool way to search through GitHub is by language.
🌐
Reddit
reddit.com › r/github › why doesn't github search return the file that contains my search string? (newbie)
r/github on Reddit: Why doesn't github search return the file that contains my search string? (Newbie)
March 4, 2022 -

I'm just trying to get "my feet wet" a bit in browsing github.

I'm searching the repository:

emacs-mirror
mirrored from git://git.sv.gnu.org/emacs.git

Then in the upper left search text box, I do a "search in this repository" for ctf. It only gives me two files:

test/lisp/epg-resources/seckey.asc
doc/misc/mh-e.texi

However, I know that the string "ctf" is also in a file called org.el within that repository. So why doesn't it also list the file org.el? Am I misunderstanding that search function? I was looking for all references to "ctf" in the code base.

As corollary, how do I find all occurrences of a text string in a repository using github web interface?

🌐
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 › features › code-search
GitHub Code Search · GitHub
GitHub code search can search across multiple repositories and is always up to date. It understands your code, and puts the most relevant results first. Dig deeper into complex codebases with tightly integrated search, code navigation and browsing. ... Code search makes it effortless to quickly find what I'm looking for in my code, or across all of GitHub
🌐
GitHub
docs.github.com › en › search-github › searching-on-github › searching-for-repositories
Searching for repositories - GitHub Docs
August 26, 2020 - 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. With the in qualifier you can restrict your search to the repository name, repository description, repository topics, contents of the README file, or any combination of these.
🌐
Flother
flother.is › til › github-repo-regex-case-insensitive-search
How to search a GitHub repo using regular expressions or case-sensitive matching — Flother
March 18, 2023 - If you’re logged in this will actually open https://github.dev/example/foo — that is, github.dev not github.com — and set up Visual Studio Code in your browser. Once that’s ready you can open up VS Code’s search sidebar, turn on case-sensitive matching and regexes, and type bars? into the search box.
🌐
GitHub
docs2.lfe.io › v3 › search
Search | GitHub API
When searching for repositories, you can get text match metadata for the name and description fields. (See the section on text match metadata for full details.) ... { "text_matches": [ { "object_url": "https://api.github.com/repositories/3081286", "object_type": "Repository", "property": "name", ...
🌐
Hacker News
news.ycombinator.com › item
Show HN: Search code in GitHub repos using regular expressions | Hacker News
February 25, 2020 - I'm the CTO @ GitHub. Would love to talk to you about this and other things we are building in this area at GitHub · Feel free to email direct to jason at github.com
🌐
GitHub
github.blog › home › news & insights › the library › repository search on all repositories
Repository Search on all Repositories - The GitHub Blog
December 6, 2019 - To search globally, all you need to do is select the All repositories option: You may have already noticed that the command bar will also give you these options: Finally, if you didn’t find what you were looking for in your repository, you can turn a repository search into a global search by clicking Search all of GitHub.