Skip to content

Instantly share code, notes, and snippets.

@Kurtz1993
Last active October 21, 2023 21:40
Show Gist options
  • Save Kurtz1993/56509012687fa45af179755e5629d8ce to your computer and use it in GitHub Desktop.
Save Kurtz1993/56509012687fa45af179755e5629d8ce to your computer and use it in GitHub Desktop.
#!/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