How to delete merged branches in local and origin


This article describes how to delete merged branches in local and origin.

🏀 Delete all merged branches in remote

git branch -r --merged master | grep -v -e master -e develop | sed -e 's% *origin/%%' | xargs -I% git push --delete origin %
  1. Show all merged branches in master on origin
  2. I exclude master and develop because we do not want them to disappear
  3. Delete origin/***
  4. xargs (pass all branch names with -I%% and delete all)

🚌 Delete all merged branches in local

git branch --merged master | grep -vE '^\*|master$|develop$' | xargs -I % git branch -d %
  1. Show all merged branches to master on local git
  2. I exclude master and develop because we do not want them to disappear
  3. xargs (pass all branch names with -I%% and delete all)

👽 References

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!