For work I’ve created a repository with different branches for details of collections of scripts found on each server (ie the branches have different bases). I wanted to grep all files at HEAD in each of the branches; the following command does this:
git grep TERM `git for-each-ref refs/remotes/origin --format='%(refname:short)'`