diff --git a/dist/index.js b/dist/index.js
index 2ef372e..e04155f 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -4887,11 +4887,9 @@ class GitCommandManager {
     }
     isDetached() {
         return __awaiter(this, void 0, void 0, function* () {
-            // Note, this implementation uses "branch --show-current" because
-            // "rev-parse --symbolic-full-name HEAD" can fail on a new repo
-            // with nothing checked out.
-            const output = yield this.execGit(['branch', '--show-current']);
-            return output.stdout.trim() === '';
+            // Note, "branch --show-current" would be simpler but isn't available until Git 2.22
+            const output = yield this.execGit(['rev-parse', '--symbolic-full-nane', 'HEAD'], true);
+            return !output.stdout.trim().startsWith('refs/heads/');
         });
     }
     lfsFetch(ref) {
diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts
index f86b8c0..bbf0878 100644
--- a/src/git-command-manager.ts
+++ b/src/git-command-manager.ts
@@ -170,12 +170,12 @@ class GitCommandManager {
   }
 
   async isDetached(): Promise<boolean> {
-    // Note, this implementation uses "branch --show-current" because
-    // "rev-parse --symbolic-full-name HEAD" can fail on a new repo
-    // with nothing checked out.
-
-    const output = await this.execGit(['branch', '--show-current'])
-    return output.stdout.trim() === ''
+    // Note, "branch --show-current" would be simpler but isn't available until Git 2.22
+    const output = await this.execGit(
+      ['rev-parse', '--symbolic-full-nane', 'HEAD'],
+      true
+    )
+    return !output.stdout.trim().startsWith('refs/heads/')
   }
 
   async lfsFetch(ref: string): Promise<void> {