Skip to content

Instantly share code, notes, and snippets.

@greatbody
Last active January 15, 2019 03:19
Show Gist options
  • Save greatbody/5218ae10d4b7acb7053bb7dcfe761e87 to your computer and use it in GitHub Desktop.
Save greatbody/5218ae10d4b7acb7053bb7dcfe761e87 to your computer and use it in GitHub Desktop.
Say you have a project with many repos and you can run this scripts to pull all git repos inside a folder
#!/bin/sh
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
echo_green()
{
echo "${green}$1${reset}"
}
echo_red()
{
echo "${red}$1${reset}"
}
arr=($(ls -d */))
for i in "${arr[@]}"
do
# do whatever on $i
echo_green "Processing $i..."
cd $i
echo_green "Stashing..."
git stash
cbranch=$(git branch | grep \* | cut -d ' ' -f2)
echo_green "Checkout to master..."
git checkout master
echo_green "Pull latest commit(s).."
git pull
echo_green "Check out to ${cbranch} and Unstashing..."
git checkout $cbranch
git stash pop
cd ..
echo_red "------------------------------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment