Skip to content

Instantly share code, notes, and snippets.

@groupsky
Last active October 11, 2015 14:08
Show Gist options
  • Save groupsky/3871096 to your computer and use it in GitHub Desktop.
Save groupsky/3871096 to your computer and use it in GitHub Desktop.
Synch git repo
#!/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