Created
March 16, 2021 14:58
-
-
Save kilasuit/cb055e19bef793d07486a5d8255ed61d to your computer and use it in GitHub Desktop.
Functions for cleaning up local git branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function gitforcecleanbranches { | |
| [CmdletBinding()] | |
| [alias('gitcbf')] | |
| param( | |
| [switch] | |
| $Notmerged | |
| ) | |
| if ($notmerged) { | |
| git for-each-ref --format '%(refname:short)' refs/heads | ForEach-Object { if ($_ -match 'master|main') { git branch $_ -D } } | |
| } | |
| else { | |
| git for-each-ref --format '%(refname:short)' refs/heads --merged | ForEach-Object { if ($_ -match 'master|main') { git branch $_ -D } } | |
| } | |
| } | |
| function gitcleanbranches { | |
| [CmdletBinding()] | |
| [alias('gitcb')] | |
| param( | |
| [switch] | |
| $Notmerged | |
| ) | |
| if ($notmerged) { | |
| git for-each-ref --format '%(refname:short)' refs/heads | ForEach-Object { if ($_ -match 'master|main') { git branch $_ -d } } | |
| } | |
| else { | |
| git for-each-ref --format '%(refname:short)' refs/heads --merged | ForEach-Object { if ($_ -match 'master|main') { git branch $_ -d } } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment