Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a remote branch using Git?

I know this has been covered before, but I have tried the following and can't seem to delete the remote branch.

aly@neon:~/workspace/3DOD_VARIANCE$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/multi_gauss_at_nodes
  remotes/origin/old-state-with-mean-deviation-from-centre
  remotes/origin/variance-branch


aly@neon:~/workspace/3DOD_VARIANCE$ git branch -r -d origin/old-state-with-mean-deviation-from-centre Deleted remote branch origin/old-state-with-mean-deviation-from-centre (was 0ed90b2).


Fetching origin
From https://bitbucket.org/alykhantejani/3dobjectdetection
 * [new branch]      old-state-with-mean-deviation-from-centre -> origin/old-state-with-mean-deviation-from-centre

As you can see the branch has been fetched again. Any idea what I'm doing wrong?

Also, as a side note, is there a way for me to check if this branch has already been merged back into master before I delete?

like image 578
Aly Avatar asked Jul 09 '13 10:07

Aly


1 Answers

The full push command is the following

git push <remote name> <local branch>:<remote branch>

Just send "no branch at all" to the remote server that way:

git push origin :old-state-with-mean-deviation-from-centre

For the sidenote : git prevents you to delete branch that has not been merged when you use "git branch -d " (and tells you to use -D if you are really sure to delete it anyway).

Also notice the git branch -d -r <branch name> delete the references in your .git folder (and not the real branch located on the remote server), that's why a new fetch will re create it

like image 159
Asenar Avatar answered Sep 23 '22 13:09

Asenar