--- gitlab-runner-13.12.0/src/gitlab.com/gitlab-org/gitlab-runner/shells/abstract.go~ 2021-05-20 18:01:08.000000000 +0300 +++ gitlab-runner-13.12.0/src/gitlab.com/gitlab-org/gitlab-runner/shells/abstract.go 2021-09-06 17:21:01.502430880 +0300 @@ -386,7 +386,11 @@ func (b *AbstractShell) writeCheckoutCmd(w ShellWriter, build *common.Build) { w.Noticef("Checking out %s as %s...", build.GitInfo.Sha[0:8], build.GitInfo.Ref) - w.Command("git", "checkout", "-f", "-q", build.GitInfo.Sha) + if build.GitInfo.RefType == common.RefTypeTag { + w.Command("git", "checkout", "-f", "-q", build.GitInfo.Sha) + } else { + w.Command("git", "checkout", "-fq", "-B", build.GitInfo.Ref, build.GitInfo.Sha) + } cleanFlags := build.GetGitCleanFlags() if len(cleanFlags) > 0 {