Skip to content

Instantly share code, notes, and snippets.

@k3muri84
Created May 7, 2021 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k3muri84/972b895fafdfd027e53c926d4d23a0c7 to your computer and use it in GitHub Desktop.
Save k3muri84/972b895fafdfd027e53c926d4d23a0c7 to your computer and use it in GitHub Desktop.
remove merged branches
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
#!/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