Last active
October 21, 2023 21:40
-
-
Save Kurtz1993/56509012687fa45af179755e5629d8ce to your computer and use it in GitHub Desktop.
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 | |
defaultBranch=main | |
PULLBRANCH=${1:-$defaultBranch} | |
git checkout $PULLBRANCH; | |
git pull origin $PULLBRANCH; | |
# This will delete all remote branches that have been merged into the current branch. | |
# git branch -r --merged | egrep -v "(^\*|main|dev|release)" | sed 's/origin\///' | xargs -r git push --delete origin; | |
# Remove all references to unexisting remote branches. | |
echo "Fetching remote references and pruning..." | |
git fetch -p; | |
## This will remove all local branches that don't exist in the remote anymore. | |
echo "Deleting all local branches that don't exist in the remote anymore..." | |
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs -r git branch -D; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment