Search code examples
gitbranchgit-branchremote-branch

Remove all local closed branch depends on its remote status


I would like to check which of my local branch are closed on remote server and remove them from my local list - is there such git (or any other e.g.bash) command?

My current flow:

  • git branch to list my local branches
  • log in to bitbucket/github/other git hosting service and check which branches are closed
  • delete branches locally with command: git branch -d branch_name

Any tips/help will be appreciated.


Solution

  • There is

    git remote prune origin

    That will remove remote branches that track branches on the remote that are no longer there. But it won't delete local branches.

    You could clean out locally merged branches using the command suggested in this answer:

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