Skip to content

Instantly share code, notes, and snippets.

@lazyfrosch
Last active January 17, 2020 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazyfrosch/140f689a4a4526f0682f3c834ce897db to your computer and use it in GitHub Desktop.
Save lazyfrosch/140f689a4a4526f0682f3c834ce897db to your computer and use it in GitHub Desktop.
One of my favorite git shortcut, run actions on a deeper git tree with multiple repositories
#!/bin/bash
# git-all
#
# Copyright (c) 2019 Markus Frosch <markus@lazyfrosch.de>
#
# Licensed under GPL-2+
rc=0
color() {
[ -t 1 ] || return
for c in "$@"
do
echo -en "\\e[${c}m"
done
}
echo_reset() {
echo -n "$@"
[ -t 1 ] && echo -en '\e[0m'
echo
}
GIT_DIRS=()
while IFS=$'\n' read -r line
do
GIT_DIRS+=("$line")
done < <(find . -type d -name .git)
for git_dir in "${GIT_DIRS[@]}"
do
dir="$(dirname "$git_dir")"
color 97 42
echo_reset "[ $dir - git $* ]"
if ! ( cd "$dir" && git "$@" ); then
rc=$?
fi
done
exit $rc

git-all

Run a git action an all git repositories find below current work directory.

$ git-all status

$ git-all fetch

$ git-all checkout master

$ git-all pull
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment