Skip to content

Instantly share code, notes, and snippets.

@pete-otaqui
Created January 12, 2012 10:37
Show Gist options
  • Save pete-otaqui/1599786 to your computer and use it in GitHub Desktop.
Save pete-otaqui/1599786 to your computer and use it in GitHub Desktop.
Find File Path Pattern in all git branches
#!/bin/bash
# Authored by Pete Otaqui <pete@otaqui.com>
#
# Core code taken from StackOverflow
# http://stackoverflow.com/questions/372506/how-can-i-search-git-branches-for-a-file-or-directory
#
# The author has placed this work in the
# Public Domain, thereby relinquishing all
# copyrights. Everyone is free to use, modify,
# republish, sell or give away this work
# without prior consent from anybody.
usage() {
echo
echo $0 - Search for file paths in git branches
echo
echo Use this script to apply an extended regex
echo search to all file names in all local git
echo branches. Very helpful in finding files
echo that you created "somewhere" or that have
echo been moved
echo
echo Usage:
echo $0 path/to/lost_file.*
echo
}
[[ -n "$1" ]] || { usage; exit 0 ; }
for branch in `git for-each-ref --format="%(refname)" refs/heads`;
do
echo
echo $branch :;
git ls-tree -r --name-only $branch | grep -E "$1"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment