Created
May 5, 2025 14:27
-
-
Save pascalwhoop/cfad4375a76bb6a8801ed40164850c55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# 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