Why does Git use a colon (:) to delete remote branches?

It is not the meaning of the : per se, but what is present, or rather absent before it.

The refspec format is

<+><source>:<destination>

(optional + for non-fast forward)

So when you do something like git push origin :featureA, you are specifying an empty source ref and basically making the destination “empty” or deleting it.

PS: Note that the refspec of : or nothing doesn’t mean push nothing to nothing however. It makes git to push “matching” branches: for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side.

Leave a Comment

tech