Skip to content

Instantly share code, notes, and snippets.

@halferty
Last active January 17, 2018 19:09
Show Gist options
  • Save halferty/6a4dd112d0252c3fe5f80bf341c9f5b6 to your computer and use it in GitHub Desktop.
Save halferty/6a4dd112d0252c3fe5f80bf341c9f5b6 to your computer and use it in GitHub Desktop.
Reset git directory to a known state - no questions asked (have a simpler version? are you sure? what if you're in the middle of a rebase and have untracked files?)
alias nuke-nuke-branch="nnuke_branch"
alias nuke-branch="nuke_branch"
function nuke_branch()
{
if [ $# -eq 1 ]; then
git clean -f -d
git rebase --abort
git branch -D tempbranch &> /dev/null
find . -name "post-checkout" | xargs rm -rf
git checkout -b tempbranch
git fetch upstream
git branch -D $1
git checkout -b $1 --track upstream/$1
git branch -D tempbranch
git reset --hard HEAD
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment