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.
- How's your problem? Did the answer help?Nick Volynkin– Nick Volynkin2015-05-28 08:28:38 +00:00Commented May 28, 2015 at 8:28
- @NickVolynkin Your answer didn't help me. Ended up searching manually for what I was looking for.ltrainpr– ltrainpr2015-05-28 13:49:09 +00:00Commented May 28, 2015 at 13:49
- Does this answer your question? Searching code in a specific GitHub branchMichael Freidgeim– Michael Freidgeim2023-02-24 12:46:09 +00:00Commented Feb 24, 2023 at 12:46
2 Answers
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.
Comments
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.