Skip to content

Commit c8f053a

Browse files
committed
Add git-prune-remote-branch script
1 parent 2df31a7 commit c8f053a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

git-prune-remote-branch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env ruby
2+
require 'optparse'
3+
4+
opts = OptionParser.new
5+
opts.on('--noop', 'dry-run mode') { |v| $noop = true }
6+
opts.parse!
7+
8+
`git branch -r`.each_line do |branch|
9+
branch.strip!.chomp!
10+
next if branch =~ /origin\/master/
11+
next if branch =~ /origin\/develop/
12+
13+
if `git branch --contains #{branch}`.each_line.any? { |included| included.strip.chomp =~ /\A(develop|master)\z/ }
14+
ref = branch.sub(/^origin\//, '')
15+
command = "git push --delete origin #{ref}"
16+
puts command
17+
unless $noop
18+
system command
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)