Cleaning Up Git Branches

17th August 2025 · Development

When working on large codebases there are times that you need to check and/or clean up the git branches.

Whist GUI Git clients can be useful, it is often easier to list them from the command line first.

These command line commands can help in finding branches to be checked.

List all branches:

for branch in `git branch -r | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r

List merged branches:

for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r

List un-merged branches:

for branch in `git branch -r --no-merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r

To find local branches where the remote branch is gone/deleted:

git branch -vv | grep ': gone'