Skip to content

Instantly share code, notes, and snippets.

@midNight-jam
Last active November 16, 2017 00:48
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 midNight-jam/b43933291c06df5040fbe2a35c2dfc15 to your computer and use it in GitHub Desktop.
Save midNight-jam/b43933291c06df5040fbe2a35c2dfc15 to your computer and use it in GitHub Desktop.
stupd : Stash and Update, all git repos under the current dir, with stashing the changes, pulling the latest and applying the stashed changes over again.
# stash and update all the repos under this base dir
stupd(){
cur_dir=$(pwd)
echo "Location : " $cur_dir
# get all git repos under the cur dir
for i in $(find . -name ".git" | rev | cut -f 2- -d '.' | rev); do
echo 'Repo : ' $i
# switch into the git repo
cd $i
# log the current branch
git branch
# get the stashed changes count before stashing
bc=$(git stash list | wc -l)
# stash the changes, if there are any
git stash
# get the stashed changes count after stashing
ac=$(git stash list | wc -l)
# pull the latest from the current branch
git pull
# apply ur changes back from stash, this is required bcoz we want to pop only the changes we stashed
if [ $ac -gt $bc ]; then
git stash pop
fi
echo '======================================'
echo -e $i "\xE2\x9C\x94 - repo updated"
echo '======================================'
# resume to cur dir
cd $cur_dir
done
echo '[Done]'
echo ' ~\__[+_+]__/~ '
echo ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment