Skip to content

Instantly share code, notes, and snippets.

@amirsinaa
Created January 4, 2020 20:44
Show Gist options
  • Save amirsinaa/d465807602048b45249becd49beb5bbc to your computer and use it in GitHub Desktop.
Save amirsinaa/d465807602048b45249becd49beb5bbc to your computer and use it in GitHub Desktop.
Pull all git repositories located in a directory ( with extra options )
#!/bin/bash
CURRENT_DIRECTORY=$(pwd)
echo $'\e[1;31m'git reset --hard ? $'\e[0m'
read -r -p "[y/N]" reset_changes_bool
case "$reset_changes_bool" in
y|Y)
echo $'\e[1;32m'Pulling latest changes for all repositories ... $'\e[0m'
for repo in $(find . -name ".git" | cut -c 3-); do
cd "$repo";
echo "\033[34m"Pulling : @@ $repo @@"\033[0m";
cd ..;
git reset --hard && git fetch --all;
echo $'\e[1;35m'Pull [develop/master/custom] $'\e[0m'
read -r -p "?" select_origin
case "$select_origin" in
develop|DEVELOP)
git checkout develop
;;
master|MASTER)
git checkout master
;;
custom|CUSTOM)
echo $'\e[1;35m'Enter your branch name : $'\e[0m'
read customBranch
git checkout $customBranch;
;;
*)
echo $'\e[1;31m'Invalid or unknown parameter ! $'\e[0m'
;;
esac
echo $'\e[1;35m'--rebase [y/N] $'\e[0m'
read -r -p "?" pull_type
case "$pull_type" in
y|Y)
git pull --rebase
;;
n|N)
git pull
;;
*)
echo $'\e[1;31m'Invalid or unknown parameter ! $'\e[0m'
;;
esac
cd $CURRENT_DIRECTORY
done
echo $'\e[1;32m'Done ! $'\e[0m'
;;
n|N)
echo $'\e[1;35m'Fetch then ? [y/N] $'\e[0m'
read -r -p "?" fetch_or_not
case "$fetch_or_not" in
y|Y)
for repo in $(find . -name ".git" | cut -c 3-); do
cd "$repo";
echo "\033[34m"Fetching : @@ $repo @@"\033[0m";
cd ..;
git fetch --all;
cd $CURRENT_DIRECTORY
done
echo $'\e[1;32m'Done ! $'\e[0m'
;;
n|N)
echo "Bye !"
;;
*)
echo $'\e[1;31m'Invalid or unknown parameter ! $'\e[0m'
;;
esac
;;
*)
echo $'\e[1;31m'Invalid or unknown parameter ! $'\e[0m'
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment