Last Updated: November 09, 2021
· raphdg

Clean the local git repository from merged local branches and remotely deleted branches

Checkout to the main branch. The branch against which we want to check the merged branches.

git checkout <main_branch>

Get all the merged branches and safe delete (-d) them.

git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

Remove all the local branches which are remotely deleted.

git remote prune origin


git fetch -p