Skip to content

Instantly share code, notes, and snippets.

@renkin
Last active January 21, 2025 09:19
Show Gist options
  • Save renkin/4260be195bcb3e6032ba4547b2a527aa to your computer and use it in GitHub Desktop.
Save renkin/4260be195bcb3e6032ba4547b2a527aa to your computer and use it in GitHub Desktop.
Update branch "develop" and delete local orphaned branches
#!/bin/bash
MAIN_BRANCH=${1:-develop}
echo
echo "Fetching..."
git fe
echo
echo "Switching to $MAIN_BRANCH..."
git co $MAIN_BRANCH
echo
echo "Pulling $MAIN_BRANCH..."
git pull
echo
echo "Deleting local orphaned branches..."
git branch -vv | grep ': gone]' | grep -v '^\*' | awk '{ print $1; }' | xargs -r git branch -d
@renkin
Copy link
Author

renkin commented Jan 21, 2025

Simplier solution keeping simply only develop: git branch | grep -v "develop" | xargs git branch -D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment