Created
October 17, 2022 09:16
-
-
Save Sephsekla/3e2321bde9c9eb9fb814be91ca4d923e to your computer and use it in GitHub Desktop.
git cleanup-merged - Deletes all local branches that are fully merged into the remote HEAD branch.
This file contains 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
#!/bin/bash -e | |
# git cleanup-merged | |
# Deletes all local branches that are fully merged into the remote HEAD branch. | |
# Useful for a git flow workflow, allows quick deletion of completed feature branches. | |
CURRENT_BRANCH=$(git branch --show-current) | |
REMOTE_HEAD=$(git symbolic-ref --short refs/remotes/origin/HEAD) | |
DEFAULT_BRANCH=${REMOTE_HEAD#"origin/"} | |
git branch --merged $DEFAULT_BRANCH | grep -E -v "^(\*)? *($DEFAULT_BRANCH|$CURRENT_BRANCH)$" | xargs git branch -d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment