Last active
May 3, 2025 12:12
-
-
Save steipete/f87783c3ea90feba5c6920a243e2c4fe to your computer and use it in GitHub Desktop.
git ≥ 2.23‑style “nuke‑and‑pave”. Gets you out of everything, even worktrees!
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
fresh() { | |
# 0) escape half‑finished merges / rebases (no‑ops if nothing to abort) | |
git merge --abort 2>/dev/null || git rebase --abort 2>/dev/null || : | |
git fetch --prune --no-auto-maintenance --quiet origin && # 1 refs up‑to‑date fast [oai_citation:0‡git-scm.com](https://git-scm.com/docs/git-fetch) | |
git switch --discard-changes --recurse-submodules -C main origin/main && # 2 hard‑reset + checkout incl. submodules | |
git clean -ffdx && # 3 wipe every untracked/ignored artefact | |
git for-each-ref --format='%(refname:short)' --merged main refs/heads \ | |
| grep -v '^main$' | xargs -r git branch -D # 4 trash merged locals in one hit | |
clear | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lots of cool stuff in newer gits: