tags:

views:

143

answers:

2

Hello,

The command to remove a remote branch in git is the following

git push origin :/heads/[feature-name]  
       [feature-name] being the name of the branch

This does the job perfectly, true that.
However by typing it, I can make no association that what I type is actually deleting a branch.

Can you please describe why this actually works? (my question has nothing to do with how it is implemented)

Understanding this, will hopefully help me get a better grasp of how git works.

+4  A: 

The format of git push (for our part) is :

git push <repository> <src>:<dst>

So using git push origin :/heads/[feature-name] says to git to push a empty branch to the feature-name branch of origin. So you clean it.

Matthieu Gautier
aha, finally it makes sense to me!
hasen j
A: 

The name of the branch is a label pointing to the commit SHA. You are effectively removing that label. As there is no label in maintaining that branch, it is trashed and is lost.

That aside, the "delete" command is defined to have that syntax, as described in the man page for git push:

git push origin :experimental Find a ref that matches experimental in the origin repository (e.g. refs/heads/experimental), and delete it.

Alternatively the --delete option could be used.

gpampara