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='
[email protected]:lelanthran/askme.git
[email protected]:lelanthran/cgui.git
[email protected]:lelanthran/lola.git
[email protected]:lelanthran/csl.git
[email protected]:lelanthran/HuntTheWumpus.git
[email protected]:lelanthran/libamq.git
[email protected]:lelanthran/libcmq.git
[email protected]:lelanthran/libds.git
[email protected]:lelanthran/libezsql.git
[email protected]:lelanthran/libnetcode.git
[email protected]:lelanthran/libsqldb.git
[email protected]:lelanthran/libxcgi.git
[email protected]:lelanthran/mysqlshim.git
[email protected]:lelanthran/rotsit.git
[email protected]:lelanthran/rtfe.git
[email protected]:lelanthran/skeleton-c.git
[email protected]:lelanthran/terminal-todo.git
[email protected]:lelanthran/web.c.git
[email protected]:lelanthran/v.js.git
[email protected]:lelanthran/libapplog.git
[email protected]:lelanthran/swish.git
[email protected]: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