diff --git a/includes/VersioncontrolGitBackend.php b/includes/VersioncontrolGitBackend.php
index f6b26dd..a38493e 100644
--- a/includes/VersioncontrolGitBackend.php
+++ b/includes/VersioncontrolGitBackend.php
@@ -12,6 +12,7 @@ class VersioncontrolGitBackend extends VersioncontrolBackend {
     );
 
   public $classesControllers = array(
+    'repo' => 'VersioncontrolGitRepositoryController',
     'operation' => 'VersioncontrolGitOperationController',
     'item' => 'VersioncontrolGitItemController',
   );
diff --git a/includes/VersioncontrolGitRepository.php b/includes/VersioncontrolGitRepository.php
index a93f1f0..ea04a9b 100644
--- a/includes/VersioncontrolGitRepository.php
+++ b/includes/VersioncontrolGitRepository.php
@@ -3,6 +3,78 @@
 class VersioncontrolGitRepository extends VersioncontrolRepository {
 
   /**
+   * The branch name of the default (HEAD) branch or empty if this information
+   * is not available.
+   */
+  public $default_branch = 'master';
+
+  protected function backendDelete($options) {
+    db_delete('versioncontrol_git_repositories')
+      ->condition('repo_id', $this->repo_id)
+      ->execute();
+  }
+
+  protected function backendUpdate($options) {
+    db_update('versioncontrol_git_repositories')
+      ->condition('repo_id', $this->repo_id)
+      ->fields(array('default_branch' => $this->default_branch))
+      ->execute();
+  }
+
+  protected function backendInsert($options) {
+    db_insert('versioncontrol_git_repositories')
+      ->fields(array(
+        'repo_id' => $this->repo_id,
+        'default_branch' => $this->default_branch,
+      ))
+      ->execute();
+  }
+
+  /**
+   * Get the default (HEAD) branch of the repository.
+   *
+   * @return
+   *   The name of the default branch or empty if there is none.
+   */
+  public function getDefaultBranch() {
+    return $this->default_branch;
+  }
+
+  /**
+   * Changes the default branch. Note that this is an async operation.
+   *
+   * @param $branch_name
+   *   The name of the branch that should be checked out by default, when the
+   *   repository is closed.
+   *
+   * @throws Exception
+   *   If the branch doesn't exist.
+   */
+  public function setDefaultBranch($branch_name) {
+    // Ensure the branch exists.
+    if (!$this->loadBranches(NULL, array('name' => $branch_name))) {
+      throw new Exception(t('The branch %branch_name doesn\'t exist.', array('%branch_name' => $branch_name)));
+    }
+
+    // The job to be queued.
+    $job = array(
+      'operation' => array(
+        'setDefaultBranch' => array($branch_name),
+        'save' => array(),
+      ),
+      'repository' => $this,
+    );
+
+    // Queue the write operation on the database an the repository.
+    drupal_queue_include();
+    $queue = DrupalQueue::get('versioncontrol_repomgr');
+    if (!$queue->createItem($job)) {
+      watchdog('versioncontrol_git', t('Failed to enqueue a default branch change for the Git repository at %root.', array('%root' => $this->root)));
+      throw new Exception(t('An error occured while attempting to enqueue switching the default branch.'), 'error');
+    }
+  }
+
+  /**
    * State flag indicating whether or not the GIT_DIR variable has been pushed
    * into the environment.
    *
diff --git a/includes/VersioncontrolGitRepositoryController.php b/includes/VersioncontrolGitRepositoryController.php
new file mode 100644
index 0000000..a8dc33b
--- /dev/null
+++ b/includes/VersioncontrolGitRepositoryController.php
@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * @file
+ *
+ * Extends VersioncontrolRepositoryController with Git specific features.
+ */
+
+class VersioncontrolGitRepositoryController extends VersioncontrolRepositoryController {
+
+  /**
+   * Extends the base query with the git backend's additional data in
+   * {versioncontrol_git_repositories}.
+   *
+   * @return SelectQuery
+   */
+  protected function buildQueryBase($ids, $conditions) {
+    $query = parent::buildQueryBase($ids, $conditions);
+    $alias = $query->leftJoin('versioncontrol_git_repositories', 'vcgr', 'base.repo_id = vcgr.repo_id');
+    $query->fields($alias, drupal_schema_fields_sql('versioncontrol_git_repositories'));
+    return $query;
+  }
+}
diff --git a/includes/VersioncontrolGitRepositoryManagerWorkerInterface.php b/includes/VersioncontrolGitRepositoryManagerWorkerInterface.php
index 923afae..342449d 100644
--- a/includes/VersioncontrolGitRepositoryManagerWorkerInterface.php
+++ b/includes/VersioncontrolGitRepositoryManagerWorkerInterface.php
@@ -41,6 +41,22 @@ interface VersioncontrolGitRepositoryManagerWorkerInterface extends Versioncontr
   public function setDescription($description);
 
   /**
+   * Switches the default (HEAD) branch to the given one.
+   *
+   * @param $branch_name
+   *   The name of the branch as under refs/heads, i.e. master.
+   */
+  public function setDefaultBranch($branch_name);
+
+  /**
+   * Reads the default branch from the Git repository.
+   *
+   * @return
+   *   The name of the branch as under refs/heads HEAD points to.
+   */
+  public function fetchDefaultBranch();
+
+  /**
    * Relocate the repository on disk to the new target location, then optionally
    * update the repository record in the database.
    */
diff --git a/includes/plugins/repomgr/VersioncontrolGitRepositoryManagerWorkerDefault.class.php b/includes/plugins/repomgr/VersioncontrolGitRepositoryManagerWorkerDefault.class.php
index 09ece99..a89fc03 100644
--- a/includes/plugins/repomgr/VersioncontrolGitRepositoryManagerWorkerDefault.class.php
+++ b/includes/plugins/repomgr/VersioncontrolGitRepositoryManagerWorkerDefault.class.php
@@ -91,6 +91,63 @@ class VersioncontrolGitRepositoryManagerWorkerDefault implements VersioncontrolG
     return TRUE;
   }
 
+  public function setDefaultBranch($branch_name) {
+    $this->passthru('symbolic-ref --quiet HEAD ' . escapeshellarg('refs/heads/' . $branch_name), TRUE);
+    $this->repository->default_branch = $branch_name;
+  }
+
+  public function fetchDefaultBranch() {
+    // Prepare the git name-rev command to get the branch referenced by HEAD.
+    $command = escapeshellcmd(_versioncontrol_git_get_binary_path() . ' symbolic-ref --quiet HEAD');
+
+    // Execute it in the git repository using proc_open.
+    $descriptor_spec = array(
+      1 => array('pipe', 'w'),
+      2 => array('pipe', 'w'),
+    );
+    $env = array(
+      'GIT_DIR' => $this->repository->root,
+    );
+    $process = proc_open($command, $descriptor_spec, $pipes, $this->repository->root, $env);
+    if (!is_resource($process)) {
+      $vars = array('%root' => $this->repository->root);
+      watchdog('versioncontrol', 'Failed to execute git symbolic-ref in %root.', $vars, WATCHDOG_ERROR);
+      throw new Exception(t('Failed to execute git symbolic-ref in %root.', $vars));
+    }
+
+    // Read from the output streams and close them.
+    $stdout = stream_get_contents($pipes[1]);
+    $stderr = stream_get_contents($pipes[2]);
+    fclose($pipes[1]);
+    fclose($pipes[2]);
+
+    // The exit code must be 0.
+    if ($ret = proc_close($process)) {
+      $vars = array(
+        '%root' => $this->repository->root,
+        '%ret' => $ret,
+        '%stdout' => $stdout,
+        '%stderr' => $stderr,
+      );
+      watchdog('versioncontrol', "git symbolic-ref exited with return code %ret in %root, emitting stdout:\n%stdout\n\nand stderr:\n%stderr", $vars, WATCHDOG_ERROR);
+      throw new Exception(t('git-symbolic-ref exited with return code %ret in %root.', array_slice($vars, 0, 2)));
+    }
+
+    // Stdout should be refs/heads/<branchname>.
+    if (!preg_match('/^refs\/heads\/(.*)$/', $stdout, $match)) {
+      $vars = array(
+        '%root' => $this->repository->root,
+        '%stdout' => $stdout,
+      );
+      watchdog('versioncontrol', 'Output of git-symbolic ref HEAD in %root was %stdout, which is not under refs/heads/.', $vars, WATCHDOG_ERROR);
+      throw new Exception(t('Output of git-symbolic ref HEAD in %root was %stdout, which is inot under refs/heads/.', $vars));
+    }
+
+    // Set it on the repository object and return it.
+    $this->repository->default_branch = $match[1];
+    return $this->repository->default_branch;
+  }
+
   public function passthru($command, $exception = FALSE) {
     $command = escapeshellcmd(_versioncontrol_git_get_binary_path() . ' ' . $command);
 
diff --git a/versioncontrol_git.info b/versioncontrol_git.info
index 1ae170e..4e35c2c 100644
--- a/versioncontrol_git.info
+++ b/versioncontrol_git.info
@@ -2,6 +2,7 @@ name = "Git backend"
 description = "Git backend for Version Control API - Provides Git commit information and account management as a pluggable backend."
 core=6.x
 dependencies[] = versioncontrol
+dependencies[] = drupal_queue
 package = Version Control
 vcapi-backend = 1
 files[] = includes/VersioncontrolGitAccount.php
@@ -11,4 +12,5 @@ files[] = includes/VersioncontrolGitItem.php
 files[] = includes/VersioncontrolGitItemController.php
 files[] = includes/VersioncontrolGitOperation.php
 files[] = includes/VersioncontrolGitOperationController.php
+files[] = includes/VersioncontrolGitRepositoryController.php
 files[] = includes/VersioncontrolGitRepositoryManagerWorkerInterface.php
diff --git a/versioncontrol_git.install b/versioncontrol_git.install
index 04b0dda..de22076 100644
--- a/versioncontrol_git.install
+++ b/versioncontrol_git.install
@@ -240,3 +240,27 @@ function versioncontrol_git_update_6203() {
 
   return $ret;
 }
+
+/**
+ * Reads the default branches from all existing Git repositories to synchronize
+ * the database.
+ */
+function versioncontrol_git_update_6204() {
+  // Get the repository manager queue.
+  drupal_queue_include();
+  $queue = DrupalQueue::get('versioncontrol_repomgr');
+
+  // Load all git repositories and add them to the queue.
+  $repos = versioncontrol_repository_load_multiple(NULL, array('vcs' => 'git'));
+  foreach ($repos as $repo) {
+    $queue->createItem(array(
+      'operation' => array(
+        'fetchDefaultBranch' => array(),
+        'save' => array(),
+      ),
+      'repository' => $repo,
+    ));
+  }
+
+  return array();
+}
