Last active
May 16, 2022 16:32
-
-
Save paulera/fed7e4f8ac150dd2a05180ae1ac241b1 to your computer and use it in GitHub Desktop.
Script to show the current branch of all subfolders that are git repos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will show the current branch of all subdirs in a directory | |
# source: https://gist.github.com/paulera/fed7e4f8ac150dd2a05180ae1ac241b1 | |
if [ "$1" == "--help" ] | |
then | |
echo "List the current branch of all subfolders that are GIR repos" | |
echo "Usage: $(basename $0) [folder]" | |
echo | |
echo "folder: Optional, folder to run this script on. If ommited" | |
echo " runs in the working dir" | |
echo "" | |
exit 1 | |
fi | |
if [ ! -z $1 ] | |
then | |
if [ ! -d "$1" ] | |
then | |
echo "The directory $1 doesn't exist" | |
echo "" | |
exit 1 | |
else | |
cd "$1" | |
fi | |
fi | |
FOLDER=$(pwd) | |
COUNT=0 | |
for dir in */; | |
do | |
cd $dir | |
# If it is a git repo, show branch info | |
if [ -d .git ]; then | |
COUNT=$(( COUNT + 1 )) | |
DIR=$(echo $dir | sed 's/\/$//') | |
BRANCH=$(git branch --show-current) | |
echo $DIR : $BRANCH | |
fi | |
cd .. | |
done | |
if [ "$COUNT" == "0" ]; | |
then | |
echo "No GIT repositories found in "$FOLDER | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment