It's missing:
git diff > ../i-messed-up.patch
cd .. && rm -rf $REPO
git clone $REMOTE
cd $REPO && git apply ../i-messed-up.patch