Merge "Replace ci.o.o links with docs.o.o/infra"
diff --git a/zuul/lib/cloner.py b/zuul/lib/cloner.py
index 67e238a..39e2e34 100644
--- a/zuul/lib/cloner.py
+++ b/zuul/lib/cloner.py
@@ -125,9 +125,14 @@
 
         repo = self.cloneUpstream(project, dest)
 
-        repo.reset()
         # Ensure that we don't have stale remotes around
         repo.prune()
+        # We must reset after pruning because reseting sets HEAD to point
+        # at refs/remotes/origin/master, but `git branch` which prune runs
+        # explodes if HEAD does not point at something in refs/heads.
+        # Later with repo.checkout() we set HEAD to something that
+        # `git branch` is happy with.
+        repo.reset()
 
         indicated_branch = self.branch or self.zuul_branch
         if project in self.project_branches: