EN
Git - remove all local branches that are not master branch
4
points
To remove all local branches that are not master branch execute following code:
git checkout master && git branch | grep -v master | xargs git branch -D && git remote update --prune
Where:
git checkout master
switches tomasterbranch,git branch
lists all local branchesgrep -v master
filters list returning all nonmasterbranchesxargs git branch -D
deletes with force all local branches passing as arguments forgit branch -Dresult fromgrep -v master(it is like:git branch -D local_branch_1 local_branch_2 local_branch_3etc.),git remote update --prune
updates repository removing locally unused informations about remote-tracking branch names that do not correspond to remote repository.