Skip to content

Instantly share code, notes, and snippets.

/gitfind.sh Secret

Created September 19, 2011 17:10
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save anonymous/62d981890eccb48a99dc to your computer and use it in GitHub Desktop.
Save anonymous/62d981890eccb48a99dc to your computer and use it in GitHub Desktop.
Search all branches in a git repository for a filename with a specific regex
#!/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
@redheli
Copy link

redheli commented Oct 2, 2013

it works. Thanks man!

@bstansberry
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment