Languages
[Edit]
EN

Git - remove all local branches that are not master branch

4 points
Created by:
Sujay
512

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 to master branch,
  • git branch
    lists all local branches
  • grep -v master
    filters list returning all non master branches
  • xargs git branch -D
    deletes with force all local branches passing as arguments for git branch -D result from grep -v master (it is like: git branch -D local_branch_1 local_branch_2 local_branch_3 etc.),
  • git remote update --prune
    updates repository removing locally unused informations about remote-tracking branch names that do not correspond to remote repository.

See also:

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Git

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join