Last active
June 15, 2024 10:07
-
-
Save RefusesNames/af3d5a45bef73b8d97e1000dc0e5b44f to your computer and use it in GitHub Desktop.
This function allows to delete local branches that have already been merge to (local) main. To ensure that no important branches are deleted, the names are written to a temporary file that can be edited via nvim. The branches remaining in that file are deleted (except for main)
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 delete-branches { | |
| git switch main | |
| git branch --merged > tmp.txt | |
| nvim tmp.txt | |
| Get-Content tmp.txt | ForEach-Object { | |
| $to_delete = $_.Trim() | |
| if ($to_delete -ne "* main" -and $to_delete -ne "main") { | |
| echo "Deleting $($to_delete)" | |
| git branch -d $to_delete | |
| } | |
| } | |
| git switch - | |
| rm tmp.txt | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment