Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search on GitHub to get exact string matches, including special characters

Tags:

github

search

I can search exact matches from Google by using quotes like "system <<-".

How can I do the same thing for GitHub?

Update

GitHub's code search tool now supports literal string search as of 2022.

enter image description here

like image 504
Just a learner Avatar asked Oct 17 '14 21:10

Just a learner


People also ask

How do I do an advanced search on GitHub?

Searching using a visual interface You can search GitHub Enterprise Server using the search page ( https://[hostname]/search ) or advanced search page ( https://[hostname]/search/advanced ). The advanced search page ( https://[hostname]/search/advanced ) provides a visual interface for constructing search queries.

How do I search the contents of a file in GitHub?

You can search for a file in a repository using the file finder. To search for a file in multiple repositories on GitHub, use the filename code search qualifier.


2 Answers

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:go is not valid, while amazing language:go is.
  • 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.

Clone and use 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 
like image 174
17 revs, 13 users 59% Avatar answered Sep 22 '22 13:09

17 revs, 13 users 59%


You can use Google directly.

How about this?

"your_string_to_search" site::https://github.com "your_string_to_search" site::https://gist.github.com 
like image 26
mrgloom Avatar answered Sep 19 '22 13:09

mrgloom