Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search for specific code in a specific branch in a Github repository?

Tags:

github

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.

like image 212
ltrainpr Avatar asked May 13 '15 17:05

ltrainpr


People also ask

How do I see all branches of a git repository?

The.git structure will then include all the branches done on that repository. To use a specific branch do git checkout [branch_name] If the branch exists the files will be made available locally (as just that, the current files in the project directories). git status will then show which branch is the current branch, for example:

How to search for a specific line in a GitHub repository?

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. 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.

How to search code in specific branch on GitHub?

Perhaps using API. So far no option to search code in specific branch. See here Not from the GitHub web interface itself, as mentioned in "How can I search for a commit message on GitHub?": only the default branch (generally master) is indexed.

How do I fetch a specific branch from a repository?

You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch. With this, you fetch all the branches in the repository, checkout to the one you specified, and the specific branch becomes the configured local branch for git push and git pull .


1 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.

like image 59
RATHI Avatar answered Sep 29 '22 14:09

RATHI