              straight--vc-git-primary-remote
              "--no-checkout" url)
             (let ((default-directory repo-dir))
-              (unless (straight--check-call "git" "checkout" branch)
-                (straight--warn "Could not check out branch %S of repository %S"
-                                branch local-repo)
-                (straight--get-call "git" "checkout" "HEAD"))
+              (when commit
+                (unless (straight--check-call
+                         "git" "checkout" commit)
+                  (straight--warn
+                   "Could not check out commit %S in repository %S"
+                   commit local-repo)
+                  ;; We couldn't check out the commit, best to proceed
+                  ;; as if we weren't given one.
+                  (setq commit nil)))
+              (unless commit
+                (unless (straight--check-call
+                         "git" "checkout" branch)
+                  (straight--warn
+                   "Could not check out branch %S of repository %S"
+                   branch local-repo)
+                  ;; Since we passed --no-checkout, we need to
+                  ;; explicitly check out *something*, even if it's
+                  ;; not the right thing.
+                  (straight--get-call "git" "checkout" "HEAD")))
               (unless nonrecursive
                 (straight--get-call
                  "git" "submodule" "update" "--init" "--recursive"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Git backend API methods

(defun straight--vc-git-clone (recipe)
  "Clone local REPO for straight.el-style RECIPE."
  (straight--with-plist recipe
      (local-repo repo host branch upstream nonrecursive)
    (let ((success nil)


(defun straight--vc-clone (recipe)
  "Clone the local repository specified by straight.el-style RECIPE.
If a commit is specified in one of the lockfiles, attempt to
check out that revision. If this fails, signal a warning.

This method sets `default-directory' to the repos directory and
delegates to the relevant `straight--vc-TYPE-clone' method, where
TYPE is the `:type' specified in RECIPE. If the repository
already exists, throw an error."
  (straight--with-plist recipe
      (type local-repo)
    (let ((default-directory (straight--dir "repos"))
          (commit nil))
      (when (file-exists-p (straight--dir "repos" local-repo))
        (error "Repository already exists: %S" local-repo))
      ;; We're reading the lockfiles inline here, instead of caching
      ;; them like we do with the build cache. The reason is that
      ;; reading the lockfiles appears to be much faster than reading
      ;; the build cache, and also time is not really a concern if
      ;; we're already going to be cloning a repository.
      (dolist (spec straight-profiles)
        (cl-destructuring-bind (_profile . versions-lockfile) spec
          (let ((lockfile-path (straight--file "versions" versions-lockfile)))
            (when-let ((versions-alist (with-temp-buffer
                                         (insert-file-contents-literally
                                          lockfile-path)
                                         (ignore-errors
                                           (read (current-buffer))))))
              (when-let ((frozen-commit
                          (cdr (assoc local-repo versions-alist))))
                (setq commit frozen-commit))))))
      (straight--vc 'clone type recipe commit))))

(defun straight--vc-normalize (recipe)
  "Normalize the local repository specified by straight.el-style RECIPE.
