Last active
November 16, 2017 00:48
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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