Skip to content

Instantly share code, notes, and snippets.

@jippi
Created May 11, 2012 15:42
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 jippi/2660520 to your computer and use it in GitHub Desktop.
Save jippi/2660520 to your computer and use it in GitHub Desktop.
Sync a github fork with all changes from the fork source
#!/bin/sh
# Settings
#
fork_source_remote_name="origin"
my_form_remote_name="mine"
git_default_param=" -q "
#### Stolen from git flow ( https://github.com/nvie/gitflow/ ) ###
escape() {
echo "$1" | sed 's/\([\.\$\*]\)/\\\1/g'
}
has() {
local item=$1; shift
echo " $@ " | grep -q " $(escape $item) "
}
git_local_branches() { git branch --no-color | sed 's/^[* ] //'; }
git_local_branch_exists() { has $1 $(git_local_branches); }
git_remote_origin_branches() { git branch -r --no-color | sed 's/^[* ] //' | grep -v mine | grep -v -- '->'; }
#### Stolen code end ####
origin_branches=`git_remote_origin_branches`
git fetch $git_default_param $fork_source_remote_name
for origin_branch in $origin_branches
do
stripped_origin_branch=`echo $origin_branch | sed 's/origin\///'`
if ! git_local_branch_exists $stripped_origin_branch
then
git checkout $git_default_param -t $origin_branch
else
git checkout $git_default_param $stripped_origin_branch
fi
git pull $git_default_param $fork_source_remote_name
git push $git_default_param $my_form_remote_name
done
git push $git_default_param $my_form_remote_name --prune
git push $git_default_param $my_form_remote_name --mirror
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment