How to delete a local or remote branch in Git
- Published on
- Separator
- •
- Reading time
- 1 min read
Deletes a local branch
git branch --delete <branch-name>
Shorthand
git branch -d <branch-name>
Force a branch to be deleted even if it hasn’t been pushed or merged yet.
git branch -D <branch-name>
Delete all branches but keeping others like “develop”, “master”
git branch | grep -v "develop" | grep -v "master" | xargs git branch -D
Deletes a remote branch
git push origin --delete <branch-name>
Conclusion
Have fun and stay tuned for the next post. Thanks for reading 😉