Skip to content

Instantly share code, notes, and snippets.

@haythamdouaihy
Last active May 4, 2018 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haythamdouaihy/79b1669e23d7758ad33653eeeafed695 to your computer and use it in GitHub Desktop.
Save haythamdouaihy/79b1669e23d7758ad33653eeeafed695 to your computer and use it in GitHub Desktop.
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