Skip to content

Instantly share code, notes, and snippets.

@re5et
Created March 7, 2013 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save re5et/5104808 to your computer and use it in GitHub Desktop.
Save re5et/5104808 to your computer and use it in GitHub Desktop.
git repo sync
#! /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