开发者

explain command for git delete remote branch

开发者 https://www.devze.com 2022-12-22 19:24 出处:网络
The command to remove a remote branch in git is the following git push origin :/heads/[feature-name] [featu开发者_如何转开发re-name] being the name of the branch

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

git push origin :/heads/[feature-name]  
       [featu开发者_如何转开发re-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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消