Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I delete a Git branch locally and remotely?

I want to delete a branch both locally and remotely.

Failed Attempts to Delete a Remote Branch*
$ git branch -d remotes/origin/bugfix
error: branch 'remotes/origin/bugfix' not found.

$ git branch -d origin/bugfix
error: branch 'origin/bugfix' not found.

$ git branch -rd origin/bugfix
Deleted remote branch origin/bugfix (was 2a14ef7).

$ git push
Everything up-to-date

$ git pull
From github.com:gituser/gitproject

[new branch] bugfix -> origin/bugfix
Already up-to-date.


What should I do differently to successfully delete the remotes/origin/bugfix branch both locally and remotely?
by

3 Answers

akshay1995
To remove a local branch from your machine:

git branch -d {the_local_branch} (use -D instead to force deleting the branch without checking merged status)

To remove a remote branch from the server:

git push origin --delete {the_remote_branch}
RoliMishra
For deleting the remote branch:

git push origin --delete <your_branch>

For deleting the local branch, you have three ways:

1: git branch -D <branch_name>

2: git branch --delete --force <branch_name> # Same as -D

3: git branch --delete <branch_name> # Error on unmerge
pankajshivnani123
You can also use the following to delete the remote branch

git push --delete origin serverfix
Which does the same thing as

git push origin :serverfix
but it may be easier to remember.

Login / Signup to Answer the Question.