Delete multiple remote branches in git

前端 未结 18 2469
轮回少年
轮回少年 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:44

    Neevek's solution is elegant, but it can be better: the solution as proposed calls 'git push' once per branch, which means an additional network round-trip per branch to be deleted. Since you're using awk anyway, why not use it to prefix the ':' and then xargs can call 'git push' exactly once and delete all the branches at once:

    Dry-run to list the branches that would be deleted:

    git branch -r | awk -F/ '/\/PREFIX/{print ":" $2}'
    

    Final solution to actually push the deletes:

    git branch -r | awk -F/ '/\/PREFIX/{print ":" $2}' | xargs git push origin
    

提交回复
热议问题