Is it possible to search all of my Git remote branches for specific file contents (not just a file, but contents within them)?
My remotes are on GitHub, in case that helps...
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands.
Git includes a grep command to search through commits to a repo as well as the local files in the repo directory: git grep. Sometimes it is useful to search for a string throughout an entire repo, e.g. to find where an error message is produced.
You can try this:
git grep 'search-string' $(git ls-remote . 'refs/remotes/*' | cut -f 2)
That will search all remote branches for search-string
. Since the symbolic reference HEAD
is mirrored, you may end up searching the same commit twice. Hopefully that's not an issue. If so, you can filter it out with:
git grep 'search-string' \ $(git ls-remote . 'refs/remotes/*' | grep -v HEAD | cut -f 2)
If you need to dig through your entire history, you can also try:
git grep 'search-string' $(git rev-list --all)
Assuming you are tracking all remote branches, this will search it in all commits:
git log --all -p | grep 'search-string'
To track all remote branches:
for remote in `git branch -r`; do git branch --track $remote; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With