#!/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