Search code examples
gitversion-controlfeature-branch

Delete remote branches in origin that have already been merged


We are using a branch named 'integration' as our master branch (we still have a master, but we're not using it for now) and we have a bunch of branches that have been created off it then merged back in and need to be deleted. I found this question about deleting local branches, but wasn't sure about applying the suggestions to my particular situation.

I think this will work, don't want to run this command and have it be wrong and screw up the repo.

$ git checkout integration

$ git branch -r --merged | grep -v integration| sed 's/origin//:/' | xargs -n 1 git push origin


Solution

  • You need to escape that /, make it ...sed 's/origin\//:/'... but otherwise, sure, that would work.

    To test stuff like this, just leave the xargs part off so you see what will happen.