Delete multiple remote branches in git

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

    This may be a duplicate answer but below tested and worked for me perfectly.

    1. Delete local branch forcefully

    git branch -D branch-name

    1. Delete Remote branch

    git push origin --delete branch-name

    1. Delete more than 1 local branch

    git branch -D branch-name1 branch-name2

    1. Delete more than 1 remote branch

    git push origin --delete branch-name1 branch-name2

    1. Delete local branch with prefix. For example, feature/*

    git branch -D $(git branch --list 'feature/*')

    git branch -D backticks $(git branch --list 'feature/*' backticks)

    1. List remote branch with prefix.

    git branch -r | grep -Eo 'feature/.*'

    1. Delete remote branch with prefix

    git branch -r | grep -Eo 'feature/.*' | xargs -I {} git push origin :{}

提交回复
热议问题