anonymous / gitfind.sh secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Search all branches in a git repository for a filename with a specific regex

View gitfind.sh
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash
# original credit to http://stackoverflow.com/questions/372506/how-can-i-search-git-branches-for-a-file-or-directory/372654#372654
# usage: "gitfind.sh <regex>"
 
LOC=refs/remotes/origin
#LOC=refs/heads # to search local branches only
 
for branch in `git for-each-ref --format="%(refname)" $LOC`; do
found=$(git ls-tree -r --name-only $branch | grep "$1")
if [ $? -eq 0 ]; then
echo ${branch#$LOC/}:; echo " $found"
fi
done

it works. Thanks man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.