Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update git repositories included in a folder after resetting hard into a branch name passed as parameter (example: master)
#!/bin/bash
# store the current dir
CUR_DIR=$(pwd)
# retrieve base repo parameter
# 1st param: alias of the remote repo URL (example: origin)
# 2nd param: remote branch name (example: master)
BASE_REPO="$1"/"$2"
# Let the person running the script know what's going on.
echo "....hard reset to " $BASE_REPO " and pulling latest into all repositories...."
# Find all git repositories and update it to the master latest revision
for i in $(find . -name ".git" | cut -c 3-); do
echo "";
echo "....pulling repo: " $i "....";
# We have to go to the .git parent directory to call the pull command
cd "$i";
cd ..;
# reset to master before pull
git checkout master
git reset --hard $BASE_REPO
# finally pull
git pull origin master;
# lets get back to the CUR_DIR
cd $CUR_DIR
done
echo "....Pulling all Repos COMPLETED!...."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment