Skip to content

Instantly share code, notes, and snippets.

@jkbmaj
Forked from douglas/update_git_repos.sh
Last active April 30, 2018 07:29
Show Gist options
  • Save jkbmaj/ce89b40cfe1312992d8270cdb6466410 to your computer and use it in GitHub Desktop.
Save jkbmaj/ce89b40cfe1312992d8270cdb6466410 to your computer and use it in GitHub Desktop.
Update all git repositories under a base directory
#!/bin/bash
# store the current dir
CURRENT_DIR=$(pwd)
if [[ $1 == '' ]] ;then
BASE_DIR=${CURRENT_DIR}
else
BASE_DIR=$1;
fi
# Let the person running the script know what's going on.
echo -e "\n\033[1mBase directory - ${BASE_DIR}\033[0m\n\033[1mPulling in latest changes for all remotes in all repositories...\033[0m\n"
# Find all git repositories and update it to the master latest revision
for GIT_DIR in $(find ${BASE_DIR} -name ".git"); do
echo -e "\n\033[33m"+${GIT_DIR}+"\033[0m";
# We have to go to the .git parent directory to call the pull command
cd "${GIT_DIR}";
cd ..;
# finally pull
git pull --all;
done
# lets get back to the CURRENT_DIR
cd ${CURRENT_DIR}
echo -e "\n\033[32mComplete!\033[0m\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment