Deleting a remote branch

后端 未结 4 1845
慢半拍i
慢半拍i 2020-12-18 06:04

When I perform branch -a:

$ git branch -a
* master
 remotes/origin/HEAD -> origin/master
 remotes/origin/hello
 remotes/origin/master
         


        
相关标签:
4条回答
  • 2020-12-18 06:44

    Note that git branch only allows for deleting local references.

     git branch -r -D origin/hello
    

    That only delete the local pointer to a remote tracking branch, but that has no influence on the remote repo content itself.
    Only the git push origin :hello, as mentioned in the other answers, would do that.

    Plus, that doesn't change the config branch.hello.fetch: it still references origin/hello, which is why the next fetch will re-create the remote tracking branch in your local repo.

    0 讨论(0)
  • 2020-12-18 06:47

    To delete a remote branch, use

    git push origin :remotebranch
    

    Everything else operates on the local repository only. In more recent versions of git, you can also

    git push origin --delete remotebranch
    

    As per the documentation, --delete means the same "as prefixing all refs with a colon".

    If you are wondering about meaning of the :, it follows the standard syntax for push. Usually, you would write

    git push origin localbranch:remotebranch
    

    but here, you replace localbranch with "nothing", effectively deleting the remote branch.

    0 讨论(0)
  • 2020-12-18 07:06

    You need to remove it from the remote with the following command:

    git push origin --delete hello
    

    When you are running git branch -rd origin/hello you are deleting your local branch only. The code above removes it from the origin repo.

    0 讨论(0)
  • 2020-12-18 07:06
    git push origin --delete somebranch
    

    is the way you delete a remote branch. If you are still on an old version of Git, you may need to use the old syntax:

    git push origin :somebranch
    

    which translates to "push nothing into somebranch on the remote pointed to by origin". The command is of the form "git push (which remote repo) (what local reference):(which remote reference). Omitting (what reference) is interpreted as "put nothing" into (which remote reference), effectively deleting it. The newer syntax is much more intuitive.

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