Search code examples
githubversion-controlbranchgithub-apibranching-and-merging

Search for commits on a branch other than master branch in github


Commits present in the master branch of any repository can be obtained by searching for it on github web UI and through github Search API.
For example when we search for this d28a36113a206f9f84cc97bc72ff84aa93f87ee8 commit, it shows that this commit resides on my code-quality-metrics project on both my owner account and on one another.

But if I search for a commit like 3b3e426deacb2fa94159232a15bbdf1a2d8ff194 which is in a branch other than master branch in my repository (which is not yet merged to master) zero results are shown in both the web UI and in the API call.

How do we search for commits that resides on branches other than master from github search api?


Solution

  • 2017: As I mentioned in "How to search for a commit message on GitHub?" (and this applies to commit themselves, not just their messages):

    Only the master branch (or default branch) is indexed for search in github.com.

    Indexing all branches of all GitHub repo would result in a search space too big to manage for now.

    How do we search for commits that resides on branches other than master from github search api?

    You don't. You would have to clone the repo and search through git commands.


    2023: gh search commits uses Searching commits, which confirms:

    When you search for commits, only the default branch of a repository is searched.