问题
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 branch is merged to my current branch.
回答1:
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 currentgit branch -r --unmerged
to do the oppositegit branch -r --no-merged
is correct for the new version ofGit
and I'm not sure whethergit branch -r --unmerged
is applicable for oldgit
.
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 <remote> :<remotebranchname>
See also the documentation of git branch for the --merged
and --unmerged
flags.
回答2:
Just to point out that for unmerged branches it seems the option now is --no-merged as explained on http://git-scm.com/docs/git-branch
来源:https://stackoverflow.com/questions/9093597/how-do-i-safely-delete-a-remote-git-branch