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 '.