Delete multiple remote branches in git

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

    Thanks to Steve and Neevek, I found a solution that worked pretty well for me I figured worth sharing:

    Steve's solution worked for me with one minor adjustment. My remotes were named origin/feature/some-feature-name so I trimmed your awk:

    git branch -r | awk -Forigin/ '/\/feature/ {print $2 $3}' | xargs -I {} git push origin :{}
    

    It's now doing a nice little delete flow:

    To github.com:project/project-name.git
    - [deleted]         feature/search-min-chars
    To github.com:project/project-name.git
    - [deleted]         feature/search-placeholder
    To github.com:project/project-name.git
    - [deleted]         feature/server-error-message
    To github.com:project/project-name.git
    - [deleted]         feature/six-point-asterisk
    

    Was wondering if anyone had any ideas for a more elegant solution, though, that might output something like this (my CLI scripting is pretty poor, so it'd take me awhile to figure this out):

    git push origin :feature/search-min-chars :feature/search-placeholder :feature/server-error-message :feature/six-point-asterisk
    

    This would result in a nice single output with one network request:

    To github.com:project/project-name.git
    - [deleted]         feature/search-min-chars
    - [deleted]         feature/search-placeholder
    - [deleted]         feature/server-error-message
    - [deleted]         feature/six-point-asterisk
    

提交回复
热议问题