How to bulk delete git branches in Linux

Source: Internet
Author: User

When you use Git, you often find that you create a large number of branches unconsciously. So, the trouble is coming, so many abandoned branches, what should be done?

You can't always do a git branch-d branchname delete it!

Here's a way to bulk delete a branch:

Git branch |grep ' branchname ' |xargs git branch-d

This is the function of the bulk deletion branch implemented through the shell Pipe command

Git branch output Current branch list

grep matches the output of Git branch, and the matching value is of course branchname

The function of the xargs is to convert the argument list to a small block fragment and pass it to another command

Therefore, this order means:

Matches the branch list to the specified branch, and then one (divided into small chunks) is passed to the command to delete the branch, which is finally deleted.

That's how we want to bulk delete the branch.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.