Search code examples
linuxgitsmartgit

Find a specific folder in all remote and local GIT branches


I have few hundreds of remote and local branches. I wonder whether there is a command to help me find a folder with a specific name in all branches.

My git version is 1.8.3.1. I also have smartgit installed if it matters.

Thanks in advance.


Solution

  • The following command will output all refs (local and remotes) that point to a commit which contains the path specified in the variable SEARCH_PATH

    SEARCH_PATH="somePath"
    
    git for-each-ref --format="%(refname)" refs/heads refs/remotes | 
       while read ref
          do 
             if [[ `git ls-tree -r --name-only $ref` =~ "$SEARCH_PATH" ]] ; then                 
               echo $ref; 
             fi
       done