--- api.drush.orig	2011-06-12 15:10:16.000000000 +0100
+++ api.drush.inc	2011-06-12 15:20:17.000000000 +0100
@@ -31,6 +31,14 @@ function api_drush_command() {
       'callback' => 'api_drush_list_branches',
       'description' => 'List API branches.',
     ),
+    'api-add-branch' => array(
+      'arguments' => array(
+        'project' => 'Project name.',
+        'branch' => 'Branch name.',
+        'branch_title' => 'Branch title.',
+        'directory' => 'Project directory',
+      ),
+    ),
   );
 }
 
@@ -84,3 +92,37 @@ function api_drush_list_branches() {
   }
   drush_print_table($rows, TRUE);
 }
+
+/**
+ * Drush command to add or update an API branch.
+ */
+function drush_api_add_branch($project, $branch_name, $branch_title, $directory) {
+  // Try to load the branch if possible.
+  $branch = api_get_branch_by_name($project, $branch_name);
+  if ($branch) {
+    if (!empty($branch->data)) {
+      $branch->data = unserialize($branch->data);
+    }
+    else {
+      $branch->data = array();
+    }
+    // This is an update.
+    $branch->title = $branch_title;
+    $branch->data['directories'] = $directory;
+    $branch->data['excluded_directories'] = '';
+  }
+  else {
+    // New branch.
+    $branch = new stdClass();
+    $branch->branch_id = 0;
+    $branch->type = 'files';
+    $branch->project = $project;
+    $branch->branch_name = $branch_name;
+    $branch->title = $branch_title;
+    $branch->data['directories'] = $directory;
+    $branch->data['excluded_directories'] = '';
+    $branch->status = TRUE;
+  }
+  api_save_branch($branch);
+  drush_log('Saved branch.');
+}
\ No newline at end of file
