git with it!

stay on top of yer codebases

i very much remember the days before internet, and even then, i remember even more of the days when internet wasn't everywhere. at any moment you might find yourself offline because someone had to use the phone, or because DSL was shit, or because comcast was shit, and it was like that, until it wasn't. but sometimes it is. (i'm not high i swear)

a side-effect was i never took 'the cloud' for granted, i still don't - i watch movies from my harddrive. i listen to music from my harddrive. all the programs and settings i usually set up on a fresh os install? hardcopies on an auxilliary harddrive.

when i discovered the joys of git - right before it stopped being a joy and instead becoming a microsoft product - the spirit of it stuck with me, and i now use it to augment my constant battle to organize my shit... but i still make sure to have hardcopies - if i have starred it on github, i likely have a local copy.

after while, keeping them updated became a chore, even more so because not every repo is routinely updated, so it was alot of work and i might only see 15% of my files actually update after manually cd-ing to every directory and running git pull.

the code

this is a somewhat cleaned up copy of a copy of a gist that i came across, and recently i rolled it into my .dotfile utilities, but i figured i would throw a copy here. i store all my repos in a single directory, so during my dotfile bootstrapping, my setup will copy this into whereever it is my gits will wind up going. the rest is straightforward: executed from the root directory, it will cd into each repo folder, and run the git pull command. as it does, the script returns the exit status, so you can see if there's a particular folder that wasn't able to update (rebasing is kind of annoying lol) - and if there was nothing to update you'll see that, and whatever does update is also shown.


# store urrent dir

# update command line, depending on how many repos are being updated, it might take a few seconds
echo "Pulling in latest changes for all repositories..."

# find all git repositories and update it to the latest revision (main)
for i in $(find . -name ".git" | cut -c 3-); do
    echo "";
    echo $i;

    # go to the .git parent dir to pull 
    cd "$i";
    cd ..;

    # pull
    git pull origin master;

    # return to original dir
    cd $CUR_DIR

echo "Complete!"

simply paste this into a file name whatever.sh, give it permissions with chmod +x whatever.sh and then run it with ./whatever.sh. voila!