Skip to content

Instantly share code, notes, and snippets.

@lelanthran
Last active June 22, 2021 14:40
Show Gist options
  • Save lelanthran/2b7e7f5fd79206a41ab5f42643bc6330 to your computer and use it in GitHub Desktop.
Save lelanthran/2b7e7f5fd79206a41ab5f42643bc6330 to your computer and use it in GitHub Desktop.
Work with many git subdirs.
#!/bin/bash
# Tool to run git on all of the sub-repos specified. Use all the standard
# git commands with this (status, branch, checkout, reset, etc) and each
# command will be run for all of the repos.
# Replace the following list of dirname=url with your own.
export URLS='
askme=git@github.com:lelanthran/askme.git
cgui=git@github.com:lelanthran/cgui.git
lola=git@github.com:lelanthran/lola.git
csl=git@github.com:lelanthran/csl.git
HuntTheWumpus=git@github.com:lelanthran/HuntTheWumpus.git
libamq=git@github.com:lelanthran/libamq.git
libcmq=git@github.com:lelanthran/libcmq.git
libds=git@github.com:lelanthran/libds.git
libezsql=git@github.com:lelanthran/libezsql.git
libnetcode=git@github.com:lelanthran/libnetcode.git
libsqldb=git@github.com:lelanthran/libsqldb.git
libxcgi=git@github.com:lelanthran/libxcgi.git
mysqlshim=git@github.com:lelanthran/mysqlshim.git
rotsit=git@github.com:lelanthran/rotsit.git
rtfe=git@github.com:lelanthran/rtfe.git
skeleton-c=git@github.com:lelanthran/skeleton-c.git
terminal-todo=git@github.com:lelanthran/terminal-todo.git
web.c=git@github.com:lelanthran/web.c.git
v.js=git@github.com:lelanthran/v.js.git
libapplog=git@github.com:lelanthran/libapplog.git
swish=git@github.com:lelanthran/swish.git
libssexp=git@github.com:lelanthran/libssexp.git
'
set -e
# If we're cloning, we don't have the dirs yet so we execute the clone and
# then exit.
if [ "$1" == "clone" ]; then
for X in $URLS; do
export URL=`echo $X | cut -f 2 -d =`
export NAME=`echo $X | cut -f 1 -d =`
echo -ne "\e[34mgit-all clone \e[31m'$NAME' \e[35m($URL)\e[29m\e[0m\n"
git clone $URL $NAME
done
exit 0
fi
# Run the following to determine what color codes to use on your terminal
# if you want to change colors.
# for X in {29..50}; do echo -ne "$X => \e[${X}m Hello World\n"; done
for X in $URLS; do
export URL=`echo $X | cut -f 2 -d =`
export NAME=`echo $X | cut -f 1 -d =`
echo -ne "\e[34mgit-all in directory \e[31m'$NAME' \e[35m($URL)\e[29m\n"
pushd $PWD &> /dev/null
export DNAME=`echo -ne "\e[34m$NAME: "`
cd $NAME && git $* | sed "s/^/$DNAME/g"
[ 0 -ne "$?" ] && exit 1
echo -ne "\e[0m"
popd &> /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment