Ruby implementation of Delete already merged Git branch script sharing _ruby Topic

Source: Internet
Author: User
Tags using git

Using Git to manage code engineering is a lot more convenient, but when you're done feature branch or finish hotfix, always forget to delete these useless branches, one by one delete really troublesome, repetitive manual labor is not in line with the programmer's style, so write a simple script. One-click Delete those unwanted branches, so that unnecessary interference information out of sight.

Which branches are deleted?

The source branch of the merge (merge) operation that was deleted. If the project is in branch A (head is a branch), Branch B has been merged into Branch A, that is, branch A contains the contents of branch B, then branch B is deleted.

Code

Copy Code code as follows:

#!/usr/bin/env Ruby
# Encoding:utf-8
Exceptbranches = [' Master ', ' pre ', ' develop ']
For branch in ' CD #{argv[0]} && git branch-l '. Split (')-[' * ']
Next if Exceptbranches.include? Branch
System ("Git branch-d #{branch}")
End

How to use

Copy Code code as follows:

Ruby Removemergedbranches.rb Your_git_project

Execution results

The results are similar to the following, and note that if you do not merge, you are prompted for warnings or errors that can be ignored.

Copy Code code as follows:

Warning:deleting Branch ' Custom ' that has been merged to
' Refs/remotes/origin/custom ', but not yet merged.
Deleted Branch Custom (was b63ab7d).
Deleted Branch Hotfix (was 340cca0).
Deleted Branch Mgit (was 86b4004).
Error:the branch ' Develop_rtl ' is not fully merged.
If you are sure your want to delete it, run ' git branch-d develop_rtl '.

Related Article

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.