Delete local and remote git branches
Delete branches one at a time, or sweep up local branches whose upstream has already been deleted.
To delete a single branch, run one of these:
# Local
git branch -d BRANCH_NAME
# Remote
git push origin -d BRANCH_NAMEBulk-clean stale local branches
After merging PRs, the remote branches get deleted but their local copies stick around. Start by pruning your remote-tracking refs so git knows which upstreams are gone:
git fetch --pruneList local branches whose upstream is now gone:
git branch -vv | grep ': gone' | awk '{print $1}'Once the list looks right, pipe it into git branch -D to delete them in one shot:
git branch -vv | grep ': gone' | awk '{print $1}' | xargs -r git branch -D-D force-deletes, which is what you want here since merged squash/rebase branches often don't look merged to your local git.
Liked this? Get the next one in your inbox.
One email every other Tuesday. Engineering, product, and what I'm shipping. Unsubscribe anytime.