RH
HomePortfolioBlog
RH

Made with ❤️ by Rupanjan Hari

Copyright © 2026 Rupanjan Hari. All rights reserved.
Back to Articles
August 31, 2023
blogknowledge

Delete all local orphan branches that has no remote upstream branch

Simple git commands to delete orphan branches that has no upstream remote branch

GIGit

For deleting all local branches that has no remote upstream branch

For Fetching the latest branch list

sh
git fetch

For removing references to all remote branches that are deleted

sh
git remote prune origin

For deleting all local branches that has no upstream remote branch

this will still give warning for unmerged branches

sh
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d

For force deleting all local branches that has no upstream remote branch

sh
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -D

Run this in Git Bash, if you are in a windows machine

NOTE: This will also remove any local branch that you created for some of your own purpose