Git checkout of a branch destroys local reference to master

Hi from CircleCI.

Apologies for this issue lingering for so long. Our team recently got enough bandwidth that I had time to look into our checkout step implementations (there is actually more than one).

Also, as it was developed in the earlier more fast moving days of the company, the test coverage of this part of our build-agent was not as good as it could be. Changing the behaviour of something as mission-critical to the platform as this, with millions of different combinations of Docker image / Git version / etc running through the system is highly challenging and risky.

Anyway, long story short, I spent a few days cranking out many test scenarios to cover the various features the checkout step actually contains, and felt in a good place after this to start trying to fix issues like this. After a staged rollout and a few more regression tests for “unexpected” features. This culminated in a fairly substantial change to the script.

I believe we have covered this scenario now, as well as several others, and I hope this long-standing issue is resolved for you all.