Finding and deleting local branches under refs/heads
Assuming that the original poster means he wants to delete local branches under refs/heads
and not remote-tracking branches under refs/remotes/origin
, then to find branches that have already been merged into origin/master
, simply use the following:
# Fetch latest copy of origin/master
$ git fetch origin
# Find merged branches
$ git branch --merged origin/master
The output will show you branches which have been merged nto origin/master
, and are thus safe to delete with git branch -d <branch>
. From the official Linux Kernel Git documentation for git branch
:
"--merged" is used to find all branches which can be safely deleted, since those branches are fully contained by HEAD.
Deleting remote-tracking branches under refs/remotes/origin
If, on the other hand, the original poster meant that he wanted to delete his remote-tracking branches, then simply pass the -p
or --prune
flags to git fetch
:
$ git fetch -p origin
From the official Linux Kernel Git documentation for git fetch
:
After fetching, remove any remote-tracking branches which no longer exist on the remote.