Skip to content

Instantly share code, notes, and snippets.

@autarch
Created February 13, 2013 16:20
Show Gist options
  • Save autarch/4945753 to your computer and use it in GitHub Desktop.
Save autarch/4945753 to your computer and use it in GitHub Desktop.
#!/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