Skip to content

Instantly share code, notes, and snippets.

@pascalwhoop
Created May 5, 2025 14:27
Show Gist options
  • Save pascalwhoop/cfad4375a76bb6a8801ed40164850c55 to your computer and use it in GitHub Desktop.
Save pascalwhoop/cfad4375a76bb6a8801ed40164850c55 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ensure we're in git root
cd "$(git rev-parse --show-toplevel)"
# zip .git folder and store in above folder
zip -r ../git_folder.zip .git
# get uncommitted changes
git diff > ../uncommitted_changes.txt
git diff main > ../branch_diff.txt
# now we reset the repo to remote
git reset --hard
git fetch --all
git checkout main
git reset --hard origin/main
git clean -fd
# Delete all local branches except 'main'
for branch in $(git branch | sed 's/\*//g' | awk '{$1=$1;print}' | grep -v "main"); do
git branch -D "$branch"
echo "Deleted local branch: $branch"
done
# Optional: Prune old refs and optimize
git remote prune origin
git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment