Skip to content

Instantly share code, notes, and snippets.

@MacoTasu
Last active September 10, 2015 04:56
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 MacoTasu/31839d90b5ae9301193c to your computer and use it in GitHub Desktop.
Save MacoTasu/31839d90b5ae9301193c to your computer and use it in GitHub Desktop.
remote branch remove script
use common::sense;
use Getopt::Long;
local $| = 1;
GetOptions(\my %opts, qw/
prod
/);
my $prod = $opts{'prod'};
sub trim {
my $val = shift;
$val =~ s/(origin\/)//g;
$val =~ s/^\s*(.*?)\s*$/$1/;
chomp($val);
return $val;
}
my @remote_branches = `git branch -r`;
my @branches = map { trim($_); } @remote_branches;
for my $branch (grep { $_ =~ /^jenkins\/*/ } @branches) {
if ($prod) {
`git push origin :$branch`;
}
else {
say $branch;
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment