I can search exact matches from Google by using quotes like "system <<-".
How can I do the same thing for GitHub?
I can search exact matches from Google by using quotes like "system <<-".
How can I do the same thing for GitHub?
You can't. The official GitHub searching rules:
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:gois not valid, whileamazing language:gois.- 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.
git-grep:git support searching in sources with git-grep command. Just clone a repository and use the command in the folder:
git grep "text-to-search"
Alternatives:
I recommend you to try ripgrep tool, it's fast and simple. Works like git-grep but looks nicer:
rg "text-to-search"
And you can use the standard grep to search any text in files:
grep -r "text-to-search" /repository
Today I was trying to look for an exact match of filter class in files named logback.xml in any repo on Github. And I came up with the following query which did the job.
"filter class" in:file filename:logback.xml
To enable exact matches with quotes you need to follow your search with the "in:file" modifier. The matches are not quite exact, the word "class" will have to follow the word "filter", but it seems there can be 0 or more spaces or symbols characters between the two words.
Adding to @mrgloom's answer, if you're looking for code in a specific programming language in Github using Google you could do something like this in Google's search bar:
Example:
intext:"%% 2 == 0" ext:R site:github.com
If your package is in debian, you can use their code search, which supports regular expressions: https://codesearch.debian.net/
If your search term is a filename or other substring which contains punctuation characters, a partial workaround to get GitHub's code search to return instances of that substring is to (1) replace the punctuation characters in your search term with spaces, and (2) enclose the search term in quotes.
For example, instead of using the search term:
repo:my_repo my_image_asset_1.svgTry:
repo:my_repo "my image asset 1 svg"This might not be a perfect solution in all cases; I imagine it might also match filenames like my-image-asset-1.svg. But depending on your use case, it might be "good enough"?