Git MCP Server
Git MCP servers enable AI models to interact with Git version control systems, providing capabilities for repository management, branch operations, commit handling, and collaborative development workflows.
Overview
The MCP Git Server enables AI models to interact directly with Git repositories through the Model Context Protocol. Git is the world's most popular distributed version control system, essential for modern software development and collaboration.
Official Server:
Developed and maintained by Anthropic
Key Features
Branch Management
Create, switch, and manage branches for feature development
Commit Operations
Stage changes, create commits, and track repository history
Change Tracking
View diffs, status, and detailed commit information
History & Logs
Access commit history and repository evolution
Available Tools
Quick Reference
| Tool | Purpose | Category |
|---|---|---|
git_status | Show working tree status | Status |
git_diff_unstaged | View unstaged changes | Diff |
git_diff_staged | View staged changes | Diff |
git_diff | Compare branches/commits | Diff |
git_add | Stage file changes | Staging |
git_reset | Unstage all changes | Staging |
git_commit | Create a commit | Commit |
git_log | View commit history | History |
git_show | Show commit contents | History |
git_create_branch | Create new branch | Branch |
git_checkout | Switch branches | Branch |
git_init | Initialize repository | Repository |
Detailed Usage
git_status▶
Show the working tree status including tracked, untracked, and modified files.
use_mcp_tool({
server_name: "git",
tool_name: "git_status",
arguments: {
repo_path: "/path/to/repo"
}
});
Returns current status of working directory with staged/unstaged changes.
git_diff_unstaged▶
View changes in the working directory that haven't been staged yet.
use_mcp_tool({
server_name: "git",
tool_name: "git_diff_unstaged",
arguments: {
repo_path: "/path/to/repo"
}
});
Shows line-by-line differences for modified files.
git_diff_staged▶
View changes that are staged and ready to be committed.
use_mcp_tool({
server_name: "git",
tool_name: "git_diff_staged",
arguments: {
repo_path: "/path/to/repo"
}
});
Shows what will be included in the next commit.
git_diff▶
Compare current state with a specific branch or commit.
// Compare with another branch
use_mcp_tool({
server_name: "git",
tool_name: "git_diff",
arguments: {
repo_path: "/path/to/repo",
target: "main"
}
});
// Compare with a specific commit
use_mcp_tool({
server_name: "git",
tool_name: "git_diff",
arguments: {
repo_path: "/path/to/repo",
target: "abc123def"
}
});
Useful for reviewing changes before merging.
git_add▶
Stage file changes for the next commit.
// Stage specific files
use_mcp_tool({
server_name: "git",
tool_name: "git_add",
arguments: {
repo_path: "/path/to/repo",
files: ["src/main.py", "README.md"]
}
});
// Stage all changes
use_mcp_tool({
server_name: "git",
tool_name: "git_add",
arguments: {
repo_path: "/path/to/repo",
files: ["."]
}
});
Files must be staged before committing.
git_commit▶
Create a new commit with staged changes.
use_mcp_tool({
server_name: "git",
tool_name: "git_commit",
arguments: {
repo_path: "/path/to/repo",
message: "Add user authentication feature"
}
});
Returns confirmation with new commit hash.
git_reset▶
Unstage all currently staged changes.
use_mcp_tool({
server_name: "git",
tool_name: "git_reset",
arguments: {
repo_path: "/path/to/repo"
}
});
Changes remain in working directory, just unstaged.
git_log▶
View commit history with customizable limit.
// Get last 10 commits (default)
use_mcp_tool({
server_name: "git",
tool_name: "git_log",
arguments: {
repo_path: "/path/to/repo"
}
});
// Get last 50 commits
use_mcp_tool({
server_name: "git",
tool_name: "git_log",
arguments: {
repo_path: "/path/to/repo",
max_count: 50
}
});
Returns array with hash, author, date, and message for each commit.
git_show▶
Display the contents of a specific commit.
// Show specific commit
use_mcp_tool({
server_name: "git",
tool_name: "git_show",
arguments: {
repo_path: "/path/to/repo",
revision: "abc123def"
}
});
// Show HEAD commit
use_mcp_tool({
server_name: "git",
tool_name: "git_show",
arguments: {
repo_path: "/path/to/repo",
revision: "HEAD"
}
});
Shows full diff and metadata for the specified revision.
git_create_branch▶
Create a new branch from current HEAD or specified starting point.
// Create from current HEAD
use_mcp_tool({
server_name: "git",
tool_name: "git_create_branch",
arguments: {
repo_path: "/path/to/repo",
branch_name: "feature-new-ui"
}
});
// Create from specific commit
use_mcp_tool({
server_name: "git",
tool_name: "git_create_branch",
arguments: {
repo_path: "/path/to/repo",
branch_name: "hotfix-bug-123",
start_point: "abc123def"
}
});
Branch is created but not automatically checked out.
git_checkout▶
Switch to a different branch.
use_mcp_tool({
server_name: "git",
tool_name: "git_checkout",
arguments: {
repo_path: "/path/to/repo",
branch_name: "main"
}
});
Updates working directory to match the target branch.
git_init▶
Initialize a new Git repository in the specified directory.
use_mcp_tool({
server_name: "git",
tool_name: "git_init",
arguments: {
repo_path: "/path/to/new/repo"
}
});
Creates .git directory and initializes empty repository.
Installation
{
"mcpServers": {
"git": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--mount", "type=bind,src=${workspaceFolder},dst=/workspace",
"mcp/git"
]
}
}
}
Volume Mounting:
The Docker configuration mounts your workspace folder so the Git server can access your repositories.
Common Use Cases
1. Feature Development Workflow
Create a feature branch, make changes, and commit:
// Create feature branch
use_mcp_tool({
server_name: "git",
tool_name: "git_create_branch",
arguments: {
repo_path: "/path/to/repo",
branch_name: "feature-user-auth"
}
});
// Switch to the new branch
use_mcp_tool({
server_name: "git",
tool_name: "git_checkout",
arguments: {
repo_path: "/path/to/repo",
branch_name: "feature-user-auth"
}
});
// Check status after making changes
use_mcp_tool({
server_name: "git",
tool_name: "git_status",
arguments: {
repo_path: "/path/to/repo"
}
});
// Stage and commit changes
use_mcp_tool({
server_name: "git",
tool_name: "git_add",
arguments: {
repo_path: "/path/to/repo",
files: ["."]
}
});
use_mcp_tool({
server_name: "git",
tool_name: "git_commit",
arguments: {
repo_path: "/path/to/repo",
message: "Add JWT authentication system"
}
});
2. Code Review Assistance
Review changes before committing or merging:
// View all unstaged changes
use_mcp_tool({
server_name: "git",
tool_name: "git_diff_unstaged",
arguments: {
repo_path: "/path/to/repo"
}
});
// View what's staged for commit
use_mcp_tool({
server_name: "git",
tool_name: "git_diff_staged",
arguments: {
repo_path: "/path/to/repo"
}
});
// Compare current branch with main
use_mcp_tool({
server_name: "git",
tool_name: "git_diff",
arguments: {
repo_path: "/path/to/repo",
target: "main"
}
});
3. Repository Analysis
Examine history and specific commits:
// Get recent commit history
use_mcp_tool({
server_name: "git",
tool_name: "git_log",
arguments: {
repo_path: "/path/to/repo",
max_count: 20
}
});
// View specific commit details
use_mcp_tool({
server_name: "git",
tool_name: "git_show",
arguments: {
repo_path: "/path/to/repo",
revision: "abc123def"
}
});
// View the most recent commit
use_mcp_tool({
server_name: "git",
tool_name: "git_show",
arguments: {
repo_path: "/path/to/repo",
revision: "HEAD"
}
});
4. Hotfix Workflow
Quickly create and apply urgent fixes:
// Create hotfix branch from main
use_mcp_tool({
server_name: "git",
tool_name: "git_checkout",
arguments: {
repo_path: "/path/to/repo",
branch_name: "main"
}
});
use_mcp_tool({
server_name: "git",
tool_name: "git_create_branch",
arguments: {
repo_path: "/path/to/repo",
branch_name: "hotfix-security-patch"
}
});
use_mcp_tool({
server_name: "git",
tool_name: "git_checkout",
arguments: {
repo_path: "/path/to/repo",
branch_name: "hotfix-security-patch"
}
});
// Make fixes, then commit
use_mcp_tool({
server_name: "git",
tool_name: "git_add",
arguments: {
repo_path: "/path/to/repo",
files: ["src/auth.py"]
}
});
use_mcp_tool({
server_name: "git",
tool_name: "git_commit",
arguments: {
repo_path: "/path/to/repo",
message: "Fix: Patch authentication vulnerability CVE-2024-1234"
}
});
5. Project Initialization
Set up a new Git repository:
// Initialize repository
use_mcp_tool({
server_name: "git",
tool_name: "git_init",
arguments: {
repo_path: "/path/to/new/project"
}
});
// Create initial commit
use_mcp_tool({
server_name: "git",
tool_name: "git_add",
arguments: {
repo_path: "/path/to/new/project",
files: ["."]
}
});
use_mcp_tool({
server_name: "git",
tool_name: "git_commit",
arguments: {
repo_path: "/path/to/new/project",
message: "Initial commit"
}
});
Best Practices
- Check Status Regularly: Use
git_statusbefore and after operations to understand repository state - Review Before Committing: Always use
git_diff_stagedto review changes before committing - Meaningful Commit Messages: Write clear, descriptive commit messages that explain the "why" not just the "what"
- Branch for Features: Create separate branches for each feature or bug fix
- Small, Focused Commits: Make atomic commits that address single concerns
- Review History: Use
git_logandgit_showto understand project evolution
Workflow Patterns
Standard Development Flow
- Create feature branch
- Make changes to files
- Check status (
git_status) - Review changes (
git_diff_unstaged) - Stage changes (
git_add) - Review staged changes (
git_diff_staged) - Create commit (
git_commit) - Review commit (
git_show HEAD)
Branch Comparison Flow
- Switch to feature branch
- Compare with main (
git_diffwith target: "main") - Review commit history (
git_log) - Examine specific commits (
git_show)
Limitations
- No Push/Pull: This server doesn't support remote operations (push, pull, fetch)
- No Merge Operations: Merging must be done outside the MCP server
- No Stash: Stashing changes is not currently supported
- Local Only: Operations are limited to local repositories
Sources
Related Articles
Puppeteer MCP Server
Puppeteer MCP servers enable AI models to perform browser automation, web scraping, testing workflows, and screenshot generation through headless Chrome/Chromium control.
Model Context Protocol (MCP): Open Standard for AI Integration
The Model Context Protocol (MCP) is an open standard enabling AI systems to connect with diverse data sources, tools, and services, eliminating custom integrations for seamless interaction.
Elasticsearch MCP Server
Elasticsearch MCP servers enable AI models to interact with Elasticsearch, providing capabilities for searching documents, analyzing indices, and managing clusters.