Forked from antonio/delete_rebased_and_merged_branches.sh
Last active
September 28, 2023 07:39
-
-
Save borisdiakur/61837a76a5302309069a558e1f8eff0a to your computer and use it in GitHub Desktop.
Deletes branches which were rebased and merged into main.
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 | |
git stash | |
git checkout main | |
git fetch | |
git pull --rebase | |
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'main$'); do | |
if [[ ! "$branch" =~ "origin/" ]]; then | |
last_commit_msg="$(git log --oneline --format=%f -1 $branch)" | |
if [[ "$(git log --oneline --format=%f | grep $last_commit_msg | wc -l)" -eq 1 ]]; then | |
git branch -D $branch | |
fi | |
fi | |
done |
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
{ | |
"name": "npx-git-tidy", | |
"description": "Deletes branches which were rebased and merged into main.", | |
"version": "1.0.0", | |
"bin": "./git-tidy.sh" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment