Take a build machine with git repository and a branch checked out. After a while, things have changed, history rewritten, stuff squashed, cherry-picked and merged somewhere else on dev machines and pushed to remote. 

Then the dev gets back to the build machine and hits the build script, which cleans, resets, fetches and then tries to pull some branch and build it. Unfortunately, this is the same branch that was already built on this machine. And since things have changed, it cannot be fast-forwarded and enters merge stage. But the dev does not care about the merge; if they could, they would just delete the repo and clone it again, then checkout the branch from remote. 

However, cloning the repo and initializing all submodules will take ages. So, how we can help them? How do you get your git repository in pristine state as after cloning it?

Possible script to solve the problem

```bash
git fetch
git clean -dfх
git submodule update --init --recursive
git reset --hard
git checkout -b $1 --track origin/$1 || echo ""
git pull  # <-- nope, would not work

```

Theoretically the `-b $1` could be changed to some `-b someuniqueid` checking out just "another" branch, and it would probably work. But this is not ideal. Ideas?