Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I have many Git branches. How do I delete branches which have already been merged? Is there an easy way to delete them all instead of deleting them one by one?

1 Answer

0 votes
by (27.5k points)

In order to delete all branches on remote that are already merged:

git branch -r --merged | grep -v master | sed 's/origin\//:/' | xargs -n 1 git push origin

In more recent versions of Git, this command can also be used:

git branch -r --merged | grep -v master | sed 's/origin\///' | xargs -n 1 git push --delete origin

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...