Created
February 13, 2013 16:20
-
-
Save autarch/4945753 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 perl | |
use strict; | |
use warnings; | |
use Cwd qw( cwd ); | |
use Git::Wrapper; | |
my ( $old, $new, $main, $remote ) = @ARGV; | |
die "Need an old and new name to rename a branch" | |
unless $old && $new; | |
my $git = Git::Wrapper->new( cwd() ); | |
my %branches = map { s/^\*?\s+//; $_ => 1 } $git->branch(); | |
$main //= 'master'; | |
$remote //= 'origin'; | |
$git->checkout($main); | |
$git->push( $remote, $old ); | |
$git->branch( '-t', $old, $remote . '/' . $old ) | |
unless $branches{$old}; | |
$git->branch( '-m', $old, $new ); | |
$git->push( $remote, $new ); | |
$git->push( $remote, ':' . $old ); | |
$git->branch( '-D', $new ) | |
unless $branches{$old}; | |
$git->remote( 'prune', 'origin' ); | |
print "\n Renamed $old to $new and pushed to origin\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment