Elaborate getting a current working copy.

The `git checkout` step from #3098 got removed by some merge, so here it is again.
Merge pull request #3535 from Bengt/patch-1

Elaborate getting a current working copy.