Created
May 11, 2012 15:42
-
-
Save jippi/2660520 to your computer and use it in GitHub Desktop.
Sync a github fork with all changes from the fork source
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/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