Skip to Content
GitDBDocs
MCP

Run parallel tasks on branches

Let several AI agents code in the same GitDB repository at once by giving each task its own branch over MCP.

Several agents can work in one GitDB repository at the same time. The idea is simple: every task gets its own branch. Each agent stages and commits on its task's branch, and finished work goes back to the default branch through a pull request. Agents work over MCP, so nobody needs a local checkout, and there are no working copies or lock files to share.

How branches keep tasks apart

  • Every tool call names its own branch. A connection has no "current branch." One connection can work on several branches, and several agents can each work on their own.
  • Staged changes are kept per branch. Changes staged on task/login-form are listed, committed, and discarded separately from changes staged on task/search-api, even when both agents use the same token.
  • A commit writes to one branch only. Committing on one task's branch never changes another task's branch.

Before you start

You need:

  • A connected agent (see Connect your AI agent) whose token has git:write or repo:write. That covers staging, committing, and creating, merging, and deleting branches. Pull requests need repo:write.
  • A repository with at least one commit. An empty repository can't be branched yet, so make the first commit on the default branch first.

An agent credential sends agent_model, the name of the AI model the agent runs as, on every call below that changes a branch: gitdb_create_branch, gitdb_commit, gitdb_merge_branches, gitdb_delete_branch, and the pull request tools, including gitdb_merge_pr and gitdb_close_pr. GitDB records it with the change. With a human credential it's optional.

Every agent's calls count toward your plan's allowance. See Fast calls, premium ops, and the 5-hour window.

Step 1: Create a branch for each task

Start each task by creating its branch from the default branch with gitdb_create_branch:

{ "name": "task/login-form", "from": "main" }
  • from can be a branch, a tag, or a commit SHA. If you leave it out, the branch starts at HEAD, the latest commit on the default branch.
  • Use a short branch name, such as task/login-form rather than refs/heads/task/login-form, and use exactly the same name in every call for that task.
  • A name that already exists is refused with already_exists. If two agents pick the same name, the second one finds out instead of quietly sharing the branch. Pick another name, or check gitdb_list_refs first.
  • With an agent credential, add agent_model to the call, as described in Before you start.

Step 2: Work on the task's branch

Pass the task's branch on every call:

ToolsArgument
Staging: gitdb_write_file, gitdb_create_file, gitdb_delete_file, gitdb_mkdir, gitdb_rmdir, gitdb_delete_dir, gitdb_unstage, gitdb_list_staged, gitdb_discard_allbranch
Committing: gitdb_commitbranch
Reading: gitdb_read_manybranch
Reading: gitdb_read_lines, gitdb_ls_dir, gitdb_grep, gitdb_find_files, gitdb_blame, gitdb_git_logref_name

A call that leaves the branch out works on the default branch. A read then shows the default branch's files, not the task's. A commit without branch commits the changes staged on the default branch, to the default branch.

When the task's changes are ready, commit them to the task's branch:

{ "branch": "task/login-form", "message": "Add the login form" }
  • gitdb_commit doesn't create branches. A branch that doesn't exist is refused with not_found, so create the branch first (step 1).
  • Changes staged on a branch can be committed only to that branch. Committing them to a different branch is refused with provenance_mismatch.
  • Staged changes stay saved on GitDB until they're committed or discarded. An agent whose connection drops can pick up where it left off.
  • An agent can commit as often as it likes. Each commit adds to the task's branch, and the default branch doesn't change until the work is merged.
  • With an agent credential, add agent_model to every commit, as described in Before you start.

To see how a task's branch differs from the default branch, use gitdb_git_diff with from set to the default branch and to set to the task's branch. For just the list of changed files, use gitdb_git_status with to_ref set to the task's branch. Both compare the two branches as they are now. If the default branch has moved on since the task branched, its newer changes show up too. Once a pull request is open, gitdb_read_pr with include_diff: true shows only the task's own changes, from where its branch started.

Step 3: Merge the work into the default branch

When a task is done, open a pull request from its branch with gitdb_create_pr, then merge it with gitdb_merge_pr. base_branch defaults to the repository's default branch. By default, the default branch's protection rule requires pull requests (see Branch protection), so a pull request is the usual way in. For who can merge a pull request and what each answer means, see Pull requests on the tools page.

Where pull requests over MCP aren't available yet, the pull request tools answer feature_disabled.

gitdb_merge_branches merges one branch into another directly, without a pull request. It's refused with forbidden when the target branch requires pull requests or approvals. The exception is an organization owner or admin, whose merge goes through unless the rule also applies to administrators. If a merge answers ref_contention, another change landed on the target branch at the same moment, so retry.

When tasks change the same files

Tasks on separate branches don't affect each other until they're merged. If two branches changed the same file, the second merge can answer conflicts, naming the conflicting files. A conflicts answer writes nothing: the default branch stays as it was, and the pull request stays open.

To merge a task that conflicts:

  1. Create a new branch from the default branch as it is now.
  2. Find what the task changed: gitdb_read_pr with include_diff: true shows the pull request's changes from where its branch started.
  3. Read the conflicting files as they are now on the new branch. Then stage the task's changes onto them on the new branch, and commit.
  4. Open a pull request from the new branch and merge it. Close the old pull request with gitdb_close_pr.

You'll get fewer conflicts if you split work so tasks change different files. You'll also get fewer if you merge each task soon after it's done, so later tasks branch from more recent code.

Keep one agent per branch

Give each agent its own branch. When two agents share a branch:

  • With the same token, they share one set of staged changes on that branch. One agent's gitdb_commit also commits the other agent's unfinished edits, and gitdb_discard_all drops both agents' changes. To keep their staged changes apart, give each agent its own token, or have each client send its own X-GitDB-Session-Id and X-GitDB-Thread-Id headers (see Connection details).
  • With separate tokens or sessions, GitDB doesn't compare one agent's staged files with the other's. If both stage the same file before either commits, the agent that commits last replaces the file with its own version. The earlier commit's changes to that file disappear from the branch, though they stay in its history.

Step 4: Clean up

Once a task's work is merged, delete its branch with gitdb_delete_branch. Pass branch and expected_sha, the full commit SHA the branch points at, which gitdb_list_refs shows. If the branch has moved since you read it, the call is refused with branch_changed and nothing is deleted.

Changes still staged on a branch aren't removed when the branch is deleted. Discard them first with gitdb_discard_all, passing the branch's name.

Repositories that sync with GitHub

This page's workflow is for repositories that don't sync with GitHub. In a GitHub-synced repository, gitdb_commit writes to your work branch gitdb/<your id>, whatever branch you name; the reply's ref_name says where the commit went. Open pull requests from that work branch, and delete branches on GitHub. See Stage and commit changes.

Instructions to give each agent

Add instructions like these to each agent's prompt, with that agent's own branch name:

You are working on the GitDB branch task/login-form.
- Pass branch: "task/login-form" to every staging tool, gitdb_read_many, and gitdb_commit.
- Pass ref_name: "task/login-form" to gitdb_read_lines, gitdb_ls_dir, gitdb_grep,
  gitdb_find_files, gitdb_blame, and gitdb_git_log.
- Never commit to the default branch. When the task is done, open a pull request
  from task/login-form with gitdb_create_pr.
- Pass agent_model (the AI model you run as) to gitdb_create_branch, gitdb_commit,
  gitdb_create_pr, and every merge, close, or branch delete.
- If a merge answers "conflicts", nothing was written. Report the conflicting files
  instead of retrying the same merge.

On this page