Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andiskiy/9893207e8aaa928535f8965f2cf043b5 to your computer and use it in GitHub Desktop.
Save andiskiy/9893207e8aaa928535f8965f2cf043b5 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