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.

Revisions

  1. pascalwhoop created this gist May 5, 2025.
    30 changes: 30 additions & 0 deletions reset_matrix_repo.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/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