Clean Git local branches

Boris HUISGEN
Boris HUISGEN
Clean Git local branches

Following the evolution of a Git repository, the branches are deleted as you go along on the server. However the local branches remains on the customer side and they must also be deleted by making sure not to delete any active branch.

Here is the git command to remove all local branches already merged and already removed on the remote:

$ git branch -r | \
    awk '{print $1}' | \
    egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | \
    awk '{print $1}' | \
    xargs git branch -d
Boris HUISGEN
Boris HUISGEN
Blog owner
  • #git