How to delete a branch in Git

Deleting branches after merging features or completing work is essential for maintaining a clean repository structure and organized Git workflow. As the creator of CoreUI, a widely used open-source UI library, I’ve managed thousands of feature branches across various projects over 25 years of development. From my expertise, the safest approach is using git branch -d for local branches and git push origin --delete for remote branches. This keeps your repository organized and prevents accumulation of outdated branches.

Use git branch -d to safely delete merged local branches.

git branch -d feature-branch
git push origin --delete feature-branch

Here git branch -d feature-branch deletes the local branch after confirming it’s been merged. Git prevents accidental deletion of unmerged work with this command. The second command removes the branch from the remote repository. Use -D instead of -d to force delete unmerged branches, but only when you’re certain the work isn’t needed.

Best Practice Note:

This is the same branch cleanup workflow we use in CoreUI projects for maintaining repository hygiene. Always ensure you’re on a different branch before deleting, and consider creating a backup tag if the branch contains important experimental work that might be needed later.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author