Created
May 7, 2021 13:29
-
-
Save k3muri84/972b895fafdfd027e53c926d4d23a0c7 to your computer and use it in GitHub Desktop.
remove merged branches
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
for branch in `git branch -r --merged develop | grep -v HEAD`;do echo -e `git show --format="%an" $branch | head -n 1` \\t$branch; done | sort |
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/sh | |
# disable dry run via DRU_RUN=false ./remove_branches.sh | |
ECHO='echo DRY_RUN would execute:' | |
# For all remote branches which are merged to develop, with some excpetions (see egrep command). | |
# instead of -merged u could also try older than x: --since "6 months ago" | |
for branch in $(git branch -r --merged develop | sed 's/^\s*//' | sed 's/^remotes\///' | egrep -v "(^\*|master|main|trunk|develop|)"); do | |
if [[ "$DRY_RUN" = "false" ]]; then | |
ECHO="" | |
fi | |
local_branch_name=$(echo "$branch" | sed 's/origin\///') | |
$ECHO git push origin --delete $local_branch_name | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment