Skip to content

Instantly share code, notes, and snippets.

@zerbitx
Created September 13, 2012 01:54
Show Gist options
  • Save zerbitx/3711359 to your computer and use it in GitHub Desktop.
Save zerbitx/3711359 to your computer and use it in GitHub Desktop.
A script for pull --rebase, cherry-pick, push from branch to branch
#!/usr/bin/env perl
use strict;
use warnings;
# Mac specific with its use of pbcopy
# usage cherry_hop branch1 testBranch defectBranch
# cherry is another script containing....
# #!/usr/bin/env zsh
# if [[ $# -eq 1 ]]; then
# lhash=`git log | head -n 1 | cut -d " " -f 2`;
# branch=$1
#
# git co $branch && git cherry-pick $lhash
# fi
sub interleave {
return @{$_[0]} unless @{$_[1]};
return @{$_[1]} unless @{$_[0]};
return shift(@{$_[0]}), shift(@{$_[1]}), &interleave;
}
sub main {
my @branches = @ARGV;
# Prepend the current branch
my $cur = `git branch | grep \\* | cut -d \\* -f 2`;
chomp($cur);
unshift(@branches,$cur);
# Setup the push/pull hops
my @push_pulls = map { " git pull --rebase origin $_ && git push origin $_ "; } @branches;
shift(@branches);
# Setup the cherry-pick hops
my @zipped = interleave(\@push_pulls,[ map { " cherry $_ " } @branches ]);
my $cmd = join('&&',@zipped) . " && git log | head -n 1 | cut -d ' ' -f 2 | pbcopy && git co $cur";
print $cmd."\n";
`$cmd`; # Make it so
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment