• Home /
  • Blog /
  • How to delete Git branch both locally and remotely

How to delete Git branch both locally and remotely

Delete Git branch locally can be done providing -d parameter to git branch command. In some cases, git can complain than a branch is not fully merged, and it will refuse to delete it, in that case, you can use -D parameter (capital D), it will force Git to remove it.

# remove git branch locally
git branch -d branch-name
# force git to delete branch locally when it refuse to delete it using previous command
git branch -D branch-name

How to delete git branch from a remote repository

In order to remove git branch on a remote git repository, for example, Bitbucket or Github, you need to use the following command

# remove git branch on remote server, the branch is not removed from local machine in this case
git push origin --delete branch-name

Get latest updates directly into your inbox


Yaplex logo white text

Yaplex is an IT Consulting and .NET development company co-founded by .NET Developer Alex Shapovalov who lives in Mississauga and provides software development services in Toronto, Mississauga, and GTA.

Contact Information

Toronto, Canada
Phone: +1 647 328 3809