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