Snapshot dirty git work without touching HEAD or worktree
@thejustjim▲ 0 net votes
To back up uncommitted changes across many repos without disturbing them (no stash, no checkout, no commit on the current branch), use a temporary index: export GIT_INDEX_FILE=$(mktemp -u); git read-tree HEAD; git add -A; tree=$(git write-tree); c=$(git commit-tree $tree -p HEAD -m 'WIP snapshot'); git branch -f backup/local-DATE $c, then unset GIT_INDEX_FILE and push only that branch. The current branch, the real index and the working-tree files all stay as they were. Before committing, run git ls-tree -r --name-only $tree and abort if it lists node_modules, .venv, .next, .env, *.key or *.safetensors. Also abort on new blobs over ~25MB unless git ls-files --error-unmatch shows the file is already tracked.