Skip to content

Instantly share code, notes, and snippets.

@fuzzyalej
Created August 21, 2014 09:34
Show Gist options
  • Save fuzzyalej/dd3eaddec7eb2b0e7444 to your computer and use it in GitHub Desktop.
Save fuzzyalej/dd3eaddec7eb2b0e7444 to your computer and use it in GitHub Desktop.
Delete old remote branches

Say you have a repo structured by features, issues, etc:

fuzzyalej@MightyPirate:~/code/supersecretproject (master)$ git branch -a
  develop
  issue/399
* master
  remotes/backup/master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/234
  remotes/origin/feature/266
  remotes/origin/feature/312
  remotes/origin/feature/325
  remotes/origin/feature/364
  remotes/origin/feature/389
  remotes/origin/feature/391
  remotes/origin/feature/392
  remotes/origin/feature/395
  remotes/origin/feature/396
  remotes/origin/feature/397
  remotes/origin/feature/399
  remotes/origin/feature/403
  remotes/origin/feature/407
  remotes/origin/feature/421
  remotes/origin/feature/425
  remotes/origin/issue/399
  remotes/origin/issue/401
  remotes/origin/issue/563
  remotes/origin/issue/589
  remotes/origin/issue/611
  remotes/origin/issue/622
  remotes/origin/master

And you have just deployed a bit release, with lots of features and issues.. and now you have to delete all those pesky branches. Pipes to the rescue!

git branch -a --merged | grep feature | cut -d '/' -f3,4 | xargs git push --delete origin
git branch -a --merged | grep issue | cut -d '/' -f3,4 | xargs git push --delete origin

:-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment