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
Written by Vinit Kumar
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#*nix
Authors

vinitcool76
1.96K

freyes12345
1.165K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#