Last active
January 18, 2019 10:32
-
-
Save a7madgamal/3f49bdda66bd437c7f25c4718088a42c to your computer and use it in GitHub Desktop.
stash changes > fetch all branches > pull all branches from remote > merge each local branch with master > pop stash > enjoy!
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
#!/usr/bin/env bash | |
I="\e[96m" | |
E="\e[90m" | |
echo -e "π€$I starting sync.. $E"; | |
CURRENT_BRANCH="`git rev-parse --abbrev-ref HEAD`" | |
STASH_RESULT="`git stash push -u -m AUTO_STASH | grep Saved`" | |
if [ -n "$STASH_RESULT" ]; then | |
echo -e "π€$I stashed changes to AUTO_STASH $E"; | |
fi | |
git fetch --all -p | |
LOCAL_BRANCHES=`git branch | cut -c 3-`; | |
BRANCHES_WITH_REMOTES=`git for-each-ref --format '%(refname:short):%(upstream:short)' 'refs/heads' | grep -v ':$'`; | |
echo $BRANCHES_WITH_REMOTES | while IFS=: read local remote; do | |
echo -e "π€$I running git checkout $local $E" | |
git checkout $local || return 1; | |
echo -e "π€$I running git pull $E" | |
git pull; | |
done | |
echo $LOCAL_BRANCHES | while IFS=: read local; do | |
echo -e "π€$I running git checkout $local $E" | |
git checkout $local || return 1; | |
echo -e "π€$I merging $local with master $E" | |
git merge master || return 1; | |
done | |
echo -e "π€$I checkingout starting branch $CURRENT_BRANCH $E" | |
git checkout $CURRENT_BRANCH | |
if [ -n "$STASH_RESULT" ]; then | |
git stash pop; | |
else | |
echo -e "π€$I no changes found. skipping stash pop $E"; | |
fi | |
echo -e "π€$I All good ππ $E"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment