Practical Web Programming

Friday, June 05, 2015

git: Delete All Local Branches that Already Merged to Master

After sometime using git and creating branches for every feature or bug, you will end up with a lot of branches. Some has been merged to the master branch and some are not. For those that been merged to master, there is no point for them to be in your local machine, so it's better to delete those so it will not clatter your local repository. To do that you just run the command below in your local repo:

git branch --merged | grep -vE "\*|\develop|\master" | xargs -n 1 git branch -d

This command will delete all local branches that are merged to master except for the current checked out branch, develop and master.

0 comments:

Recent Post