Created
October 4, 2019 04:22
-
-
Save clamstew/e16dc02bf669050634222140329b1598 to your computer and use it in GitHub Desktop.
show_git_branches_for_subfolders.sh - so you can see what branches each git project folder is on in a parent folder
This file contains 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 | |
# from https://unix.stackexchange.com/questions/183361/get-git-branch-from-several-folders-repos | |
# function git_branches() | |
# { | |
if [[ -z "$1" ]]; then | |
echo "Usage: $0 <dir>" >&2 | |
return 1 | |
fi | |
if [[ ! -d "$1" ]]; then | |
echo "Invalid dir specified: '${1}'" | |
return 1 | |
fi | |
# Subshell so we don't end up in a different dir than where we started. | |
( | |
cd "$1" | |
for sub in *; do | |
[[ -d "${sub}/.git" ]] || continue | |
echo "$sub [$(cd "$sub"; git branch | grep '^\*' | cut -d' ' -f2)]" | |
done | |
) | |
#} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment