Why Git use the colon (:) to delete remote branch

后端 未结 2 1826
春和景丽
春和景丽 2020-12-07 19:41

Why does Git use

git push  :

as in

git push origin :featureA

to delete the branch

相关标签:
2条回答
  • 2020-12-07 20:19

    The colon isn't a "delete flag". Note that git push and git pull both accept zero or more refspecs as their final argument(s). Now read about refspecs. A colon separates source from destination in a refspec. The command git push origin :foo has an empty source and essentially says "push nothing to branch foo of origin", or, in other words, "make branch foo on origin not exist".

    0 讨论(0)
  • 2020-12-07 20:30

    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.

    0 讨论(0)
提交回复
热议问题