Created
March 7, 2013 01:26
-
-
Save re5et/5104808 to your computer and use it in GitHub Desktop.
git repo sync
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 | |
checkout_dir=$1 | |
from_remote=$2 | |
to_remote=$3 | |
cd $checkout_dir | |
commands=( ) | |
function add_command { | |
commands=( "${commands[@]}" "$1" ) | |
} | |
function report { | |
echo -e "\033[1;36m" | |
echo "running: $1" | |
echo -e "\033[0;00m" | |
} | |
report "Fetching remotes" | |
git remote update | |
# branches=( master ) | |
branches=( $(git ls-remote --heads origin | sed "s|.*refs/heads/||" | tr '\n' ' ') ) | |
current_branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
report "Resetting current branch" | |
add_command "git reset --hard $from_remote/$current_branch" | |
add_command "git push -f $to_remote $current_branch" | |
for i in "${branches[@]}" | |
do | |
if [ "$i" == "$current_branch" ]; then | |
continue | |
fi | |
add_command "git branch --force $i $from_remote/$i" | |
add_command "git push -f $to_remote $i" | |
done | |
for i in "${commands[@]}" | |
do | |
report "$i" | |
echo $i | bash | |
if [ $? != "0" ]; then | |
exit $? | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment