Skip to content

Instantly share code, notes, and snippets.

@bacrossland
Created April 4, 2018 04:20
Show Gist options
  • Save bacrossland/d1fc52776eb709dffaac3e2da9127e69 to your computer and use it in GitHub Desktop.
Save bacrossland/d1fc52776eb709dffaac3e2da9127e69 to your computer and use it in GitHub Desktop.
Ruby script for removing old local and remote git branches
#!/usr/bin/ruby
branches = `git branch --list `
branches.gsub!('\n')
branches_arr = branches.split
# Removing from the branches_arr the branches you want to keep.
# Add or remove branches from here based on your need.
branches_arr.delete('*')
branches_arr.delete('development')
branches_arr.delete('master')
branches_arr.each do |b|
`git branch -d #{b}`
`git push origin --delete #{b}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment