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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 --mergedto detect all remote branches that are already merged into the currentgit branch -r --unmergedto do the oppositegit branch -r --no-mergedis correct for the new version ofGitand I’m not sure whethergit branch -r --unmergedis 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 usingSee also the documentation of
git branchfor the--mergedand--unmergedflags.