qotunw
Last Updated: February 25, 2016
·
1.603K
· vinitcool76
0474e465f54e54cc1225d67dfd5d9be5

Simple Bash Script To Get All Git Directories

This script is really useful when you have a lot of cloned directories many of which may not belong to you. This scripts finds them easily.

#! /bin/bash 

#Easy way to find the git repos that belong to me.

filename=$HOME/mygitdir.txt

find $HOME -name "*.git" -printf "%h\n" | sort -u > gitdir.txt
if [ -f "$filename" ]; then
    echo "$filename exists"
else
echo "Creating $filename";touch ~/mygitdir.txt
fi 
i=1
while read line 
    do 
   echo 
   cd $line
    #Here vinitcool76 is my github username,you can replace it with  yours
     count=`cat .git/config | grep -c  vinitcool76`
 if [ $count -ne 0 ]; then 
    echo $line>>$filename
 fi 
 i=`expr $i + 1`
done <gitdir.txt
cat ~/mygitdir.txt
Say Thanks
Respond