While writing your app, you’ll likely need to delete old, merged code branches. It’s important to maintain a healthy, clean codebase, which will boost your development team’s productivity. They won’t need to wade through obsolete branches in search of the right one, and they’ll be much less likely to make costly mistakes.
Here’s my one-line script for removing merged branches from remote (run it when you are on the latest
git branch -r --merged | grep -v master | sed 's/origin\///' | xargs -n 1 git push --delete origin
It simply lists all remote branches that have been merged to your current branch (that’s why you need to be on
master itself (
grep -v master), removes “origin/” suffix and then passes everything to
git push --delete origin.
Today’s Developers’ Notes’ tip were shared by Łukasz, Ruby on Rails developer. Stay tuned for more tidbits of knowledge in the near future!
Experts in software development
We are a 100% remote team of software development experts, providing web & mobile application development and DevOps services for international clients.