Delete multiple remote branches in git

前端 未结 18 2472
轮回少年
轮回少年 2020-12-07 07:11

I have a team member who inadvertently pushed over 150 of his local branches to our central repo. Thankfully, they all have the same prefix. Using that prefix, is there a gi

18条回答
  •  时光取名叫无心
    2020-12-07 07:46

    Dry run:

    git branch -r --list 'origin/your-branch-name/*' | sed "s/origin\///" | xargs -I {} echo {}
    

    Delete remote branches:

    git branch -r --list 'origin/your-branch-name/*' | sed "s/origin\///" | xargs -I {} git push origin --delete {}
    

    Delete only fully merged remote branches:

    git branch -r --merged --list 'origin/your-branch-name/*' | sed "s/origin\///" | xargs -I {} git push origin --delete {}
    

    Explanation:

    sed "s/origin\///" will remove origin/ from the branch name. Without stripping that away I got: remote ref does not exist

提交回复
热议问题