Last active
October 11, 2015 14:08
-
-
Save groupsky/3871096 to your computer and use it in GitHub Desktop.
Synch git repo
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
#!/bin/bash | |
set -e | |
set -x | |
git reset --hard ORIG_HEAD || echo skipping | |
git checkout . | |
rm -rf `git status -s | cut -c 4-` | |
git remote | grep clone || git remote add clone $1 | |
git fetch clone | |
git branch -a | grep -v HEAD | grep origin | while read i; do | |
branch=`echo $i | cut '-d/' -f3-`; | |
echo "syncing $branch" | |
if git branch | egrep "$branch$" | grep -v '*'; then | |
git branch -D $branch | |
fi | |
if git branch | egrep "* $branch$"; then | |
git merge origin/$branch | |
else | |
git checkout -b $branch origin/$branch | |
fi | |
git merge origin/$branch | |
if git branch -a | egrep "clone/$branch$"; then | |
git merge clone/$branch; | |
fi | |
git push clone $branch | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment