Created
October 22, 2025 11:59
-
-
Save zepadovani/ae2d15989c13c9442c319dff3b81f383 to your computer and use it in GitHub Desktop.
~/.gitconfig alias for deleting remote and local branches of a repository (you can inform a series of branches and it will check locally and in remote
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
| [alias] | |
| cleanup = "!f() { for BRANCH in \"$@\"; do echo \"\n--- Executing cleanup for branch: $BRANCH ---\"; LOCAL_DELETED=0; REMOTE_DELETED=0; if git branch -d \"$BRANCH\" 2>/dev/null; then LOCAL_DELETED=1; elif git branch -D \"$BRANCH\" 2>/dev/null; then LOCAL_DELETED=1; fi; if git push origin --delete \"$BRANCH\" 2>/dev/null; then REMOTE_DELETED=1; fi; echo \"Cleanup report for branch '$BRANCH':\"; if [ $LOCAL_DELETED -eq 1 ]; then echo \" - [SUCCESS] Local branch deleted.\"; else echo \" - [SKIPPED] Local branch did not exist or was not deleted.\"; fi; if [ $REMOTE_DELETED -eq 1 ]; then echo \" - [SUCCESS] Remote branch deleted (origin/$BRANCH).\"; else echo \" - [SKIPPED] Remote branch did not exist or was not deleted.\"; fi; done; }; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment