Delete merged git branch scripts in Ruby, rubygit

Source: Internet
Author: User

Delete merged git branch scripts in Ruby, rubygit

It is much easier to use Git to manage code projects. However, after completing the feature branch or hotfix, you always forget to delete these useless branches one by one, repetitive manual work does not conform to the programmer's style, so a simple script is written. Delete unnecessary branches with one click, so that redundant interference information is out of sight.

Which branches are deleted?

The deleted source branch is the Merge (Merge) operation. If the project is in branch A (with the HEAD of branch A), Branch B has been merged to branch A, that is, Branch A contains the content of branch B, and branch B is deleted.

Code

Copy codeThe Code is as follows:
#! /Usr/bin/env ruby
# Encoding: UTF-8
Repeated tbranches = ['master', 'pre', 'develop']
For branch in 'CD # {ARGV [0]} & git branch-l'. split ('')-['*']
Next if your tbranches. include? Branch
System ("git branch-d # {branch }")
End

Usage

Copy codeThe Code is as follows:
Ruby removeMergedBranches. rb your_git_project

Execution result

The execution result is similar to the following. Note that if the merge is not performed, a warning or error is prompted, which can be ignored.

Copy codeThe Code is as follows:
Warning: deleting branch 'custom' that has been merged
'Refs/remotes/origin/custom', but not yet merged to HEAD.
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 you 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.