How do I safely delete a remote git branch?

前端 未结 2 1387
情深已故
情深已故 2021-02-19 03:50

To delete a local branch in git I use git branch -d, but how do I safely remove a remote branch?

I would like to delete it only when the remote bra

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 04:43

    The answer is partly covered here: How can I know in git if a branch has been already merged into master?

    While that post copes with local branches, you could find remote branches that are merged or not using

    • git branch -r --merged to detect all remote branches that are already merged into the current
    • git branch -r --unmerged to do the opposite

    • git branch -r --no-merged is correct for the new version of Git and I'm not sure whether git branch -r --unmerged is applicable for old git.

    Once you found that a specific remote branch is already merged (i.e. it appears when typing git branch -r --merged), you could delete it as Michael Krelin answers using

    git push  :
    

    See also the documentation of git branch for the --merged and --unmerged flags.

提交回复
热议问题