How can I search for some text in commit messages including not fetched remote branches. I'm aware of git log --grep "search text"
but it doesn't search on remote branches if they are not fetched. Is there a way I can search commit messages from branches that are not fetched locally.
Example:
$ git branch -a
* main
remotes/origin/HEAD -> origin/main
remotes/origin/branch1
remotes/origin/branch2
remotes/origin/main
On GitHub there is a branch3
with some commits. How can I search branch3
's commit messages along with all other branches without doing git fetch origin
first.
Is there a way I can search commit messages from branches that are not fetched locally.
No, you can't search through data which you do not have, and the Git network protocol does not have remote search either – nor basically any other operation besides fetching the actual data.
The modern version of the protocol does have filtered fetching, so if you want to avoid fetching large files, --filter=
would let you fetch only the commit objects but not the files contained in them.
git fetch --filter="tree:0" origin # includes only commit messages
-or-
git fetch --filter="blob:none" origin # also includes trees (file lists)
GitHub has the data, so you could do a remote search through its API using the gh
CLI:
gh search commits --repo myuser/myrepo "search text"
This however is specific to GitHub and depends on its custom API; there is no such feature in the standard Git network protocols, generally. (GitLab-hosted repositories might have something similar but using a different tool – if they do at all.)