Dev Tools·
intermediate
·10 min read·Apr 4, 2026

How to Use the Git MCP Server for Version Control Operations

Manage local Git repositories through AI agents. Clone repos, create branches, make commits, and view diffs using the Git MCP server.

Gitversion controlcommitsbranchesdiffworkflow

Use the Git MCP Server for Version Control

The Git MCP server provides AI agents with direct access to your local Git repositories. Instead of manually staging files and writing commit messages, your agent can analyze your file modifications, suggest a semantic commit message, and execute the Git workflow automatically.

Configuration Setup

If you are using uvx (the Python UV runner) to launch the MCP server, add this to your config:

json
{
  "mcpServers": {
    "git": {
      "command": "uvx",
      "args": ["mcp-server-git", "--repository", "/absolute/path/to/your/repo"]
    }
  }
}

Managing Multiple Repositories

You can expose multiple repositories to the same agent by passing the --repository flag multiple times:

json
{
  "mcpServers": {
    "git": {
      "command": "uvx",
      "args": [
        "mcp-server-git",
        "--repository", "/absolute/path/to/frontend-repo",
        "--repository", "/absolute/path/to/backend-repo"
      ]
    }
  }
}

Available Tools

Your agent will be equipped with standard Git CLI wrappers:

ToolDescription
git_statusShow working tree status
git_diff_unstagedShow unstaged changes
git_diff_stagedShow staged changes
git_commitCreate a commit
git_addStage files
git_resetUnstage files
git_logView commit history
git_create_branchCreate a new branch
git_checkoutSwitch branches

Example Workflows

  • Code Review & Commit: "Show me the unstaged changes in the frontend repo, write a semantic commit message summarizing the changes, and commit them."
  • Branch Management: "Create a new feature branch called 'add-auth' from the main branch."
  • History Analysis: "Show the last 20 commits and summarize the major architectural changes made during this sprint."

Best Practices & Troubleshooting

  • Combining with Other Servers: Pair the Git MCP server with the Filesystem MCP server. The agent can read a GitHub issue, edit the local code file, run git_add, and git_commit all in one fluid motion.
  • Merge Conflicts: If the agent attempts a git_checkout or branch merge that results in a conflict, the JSON-RPC response will surface the git conflict error. You must manually resolve the merge conflict in your editor; do not let the AI attempt to resolve complex merge conflicts blindly.
  • Unstaged Changes: If the agent tries to switch branches while you have unstaged local edits, Git will abort the operation. Instruct the agent to stash changes first if necessary.

Using with OpenAI Codex

You can use this MCP server with the OpenAI Codex CLI by adding it to your configuration:

bash
codex mcp add --name git --command "npx -y @modelcontextprotocol/server-git /path/to/your/repo"

For a full list of recommended servers, see Best MCP Servers for OpenAI Codex.

Related Guides