Searching code in a specific GitHub branch


Git Problem Overview

I am trying to search some code in a branch in a GitHub repository.

However this indicates that I can only search the default branch.

Is there a way I can search code in non-default branch in my GitHub repository?

Git Solutions

Solution 1 - Git

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.

Your best bet is to clone the repository, and there, search in all branches (with git log -S for instance).

Solution 2 - Git

Using console, I would search for specific code in a specific branch with the following

git grep 'my_search_text' my_branch
  • my_branch should be available locally

  • git grep can perform pattern matching of high complexity (see the documentation)

Solution 3 - Git

If you know the filename you can use Find File.

enter image description here

enter image description here


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongCoder12View Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitdhiltView Answer on Stackoverflow
Solution 3 - GitSimon_WeaverView Answer on Stackoverflow