Last Updated: September 09, 2019
·
617
· christian-fei

Delete local and remote branch in git

The original tutorial can be found over here

Follow these simple steps to remove a branch both locally and remotely:

Merge and sync the latest changes

git pull

Let's see which branches are available on the local machine

Run

git branch

to get a list of the local branches.
The output looks something like this:

* master
  test

Delete the local branch

Let's say the branch you want to delete is called test, so run

git branch -d test

to delete the local branch

Delete the remote branch

Get a list of the remote branches by typing this in your terminal:

git branch -r

Then to delete a remote branch you use the git push command either with the --delete flag or prefixed with a colon:

git push origin :test

or

git push origin --delete test

As you prefer, dear visitor.