How do I delete branches which have already been merged? Can I delete them all at once, instead of deleting each branch one-by-one?
Share
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.
NOTE: You can add other branches to exclude like master and dev if your workflow has those as a possible ancestor. Usually I branch off of a "sprint-start" tag and master, dev and qa are not ancestors.
First, list locally-tracking branches that were merged in remote (consider using
-rflag to list all remote-tracking branches).You might see few branches you don’t want to remove. We can add few arguments to skip important branches that we don’t want to delete like master or a develop. The following command will skip master branch and anything that has dev in it.
If you want to skip, you can add it to the egrep command like the following. The branch
skip_branch_namewill not be deleted.To delete all local branches that are already merged into the currently checked out branch:
You can see that master and dev are excluded in case they are an ancestor.
You can delete a merged local branch with:
If it’s not merged, use:
To delete it from the remote use:
Once you delete the branch from the remote, you can prune to get rid of remote tracking branches with:
or prune individual remote tracking branches, as the other answer suggests, with: