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.
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:
{
"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:
{
"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:
| Tool | Description |
|---|---|
git_status | Show working tree status |
git_diff_unstaged | Show unstaged changes |
git_diff_staged | Show staged changes |
git_commit | Create a commit |
git_add | Stage files |
git_reset | Unstage files |
git_log | View commit history |
git_create_branch | Create a new branch |
git_checkout | Switch 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, andgit_commitall in one fluid motion. - ▸Merge Conflicts: If the agent attempts a
git_checkoutor 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:
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
How to Build a Custom MCP Server from Scratch
Learn how to create your own MCP server using the TypeScript or Python SDK. Expose custom tools and resources for AI agents to use.
Dev ToolsHow to Use the Puppeteer MCP Server for Web Scraping & Automation
Automate web browsers using the Puppeteer MCP server. Navigate websites, take screenshots, extract data, and automate web interactions through AI.
Dev ToolsHow to Set Up the GitHub MCP Server for Repository Management
Connect your AI agent to GitHub repositories. Create issues, manage pull requests, search code, and automate repository workflows through MCP.