diff --git a/src/RepositoryGit.php b/src/RepositoryGit.php
index 7e745c24..b0e6f4d6 100644
--- a/src/RepositoryGit.php
+++ b/src/RepositoryGit.php
@@ -1,7 +1,13 @@
 <?php
 class RepositoryGit extends RepositoryBase {
+  function __construct ($id, $def) {
+    parent::__construct($id, $def);
+    $this->branch = $def['branch'] ?? 'HEAD';
+    $this->branchEsc = escapeShellArg($this->branch);
+  }
+
   function timestamp () {
-    $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct");
+    $ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 {$this->branchEsc} --pretty=format:%ct");
 
     return $ts;
   }
@@ -9,7 +15,7 @@ class RepositoryGit extends RepositoryBase {
   function data () {
     $data = parent::data();
 
-    $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r");
+    $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree {$this->branchEsc}", "r");
     while ($r = fgets($d)) {
       if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t(([0-9a-zA-Z_\-]+)\.json)$/", $r, $m)) {
         $f = $m[1];
@@ -19,7 +25,7 @@ class RepositoryGit extends RepositoryBase {
           continue;
         }
 
-        $d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($f)), true);
+        $d1 = json_decode(shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:" . escapeShellArg($f)), true);
 
 	if (!$this->isCategory($d1)) {
 	  continue;
@@ -29,7 +35,7 @@ class RepositoryGit extends RepositoryBase {
       }
 
       if (preg_match("/^[0-9]{6} blob [0-9a-f]{40}\t((detailsBody|popupBody)\.html)$/", $r, $m)) {
-	$data['templates'][$m[2]] = shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($m[1]));
+	$data['templates'][$m[2]] = shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:" . escapeShellArg($m[1]));
       }
     }
     pclose($d);
@@ -42,7 +48,7 @@ class RepositoryGit extends RepositoryBase {
       $path .= '/';
     }
 
-    $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD " . escapeShellArg($path), "r");
+    $d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree {$this->branchEsc} " . escapeShellArg($path), "r");
     $ret = array();
     while ($r = fgets($d)) {
       $ret[] = chop(substr($r, 53));
@@ -53,6 +59,6 @@ class RepositoryGit extends RepositoryBase {
   }
 
   function file_get_contents ($file) {
-    return shell_exec("cd " . escapeShellArg($this->path) . "; git show HEAD:" . escapeShellArg($file));
+    return shell_exec("cd " . escapeShellArg($this->path) . "; git show {$this->branchEsc}:" . escapeShellArg($file));
   }
 }