10

I've tried to use the advanced search feature of Github, but when I search "specific text" repo:company/project/tree/specific_branch it does not return the desired results. It only seems to search master branch.

ltrainpr
  • 3,115
  • 3
  • 29
  • 40

2 Answers2

5

I too was looking for this. but this support in not available as per github help.

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.

RATHI
  • 5,129
  • 8
  • 39
  • 48
4

Update: There's Hubscovery which probably solves the problem.

I understand that you've been asking about a way to use GitHub's own tools to do the search. After a brief overview I could not find a solution there.

But any GitHub repo is a Git repo. So you are free to use the power of console commands. There's a git grep command, allowing you to search for lines matching a pattern throughout the repository.

git grep 'search-string' $(git ls-remote . 'refs/remotes/remote_name/branch_to_search_in' | cut -f 2)

Instead of remote_name/branch_to_search_in put the actual names of remote and branch.

This example is based on the code from other SO question.

Community
  • 1
  • 1
Nick Volynkin
  • 14,023
  • 6
  • 43
  • 67
  • Does a clone needed? Can it be done using a "shallow clone"? I think the asker is asking to invoke search specifically on github's server - without needing to clone the repo. If the repo is cloned, why search the server? – AlikElzin-kilaka Oct 09 '18 at 09:56