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.

GitHub starsnpm versionPyPI version

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

ToolPurposeCategory
git_statusShow working tree statusStatus
git_diff_unstagedView unstaged changesDiff
git_diff_stagedView staged changesDiff
git_diffCompare branches/commitsDiff
git_addStage file changesStaging
git_resetUnstage all changesStaging
git_commitCreate a commitCommit
git_logView commit historyHistory
git_showShow commit contentsHistory
git_create_branchCreate new branchBranch
git_checkoutSwitch branchesBranch
git_initInitialize repositoryRepository

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

  1. Check Status Regularly: Use git_status before and after operations to understand repository state
  2. Review Before Committing: Always use git_diff_staged to review changes before committing
  3. Meaningful Commit Messages: Write clear, descriptive commit messages that explain the "why" not just the "what"
  4. Branch for Features: Create separate branches for each feature or bug fix
  5. Small, Focused Commits: Make atomic commits that address single concerns
  6. Review History: Use git_log and git_show to understand project evolution

Workflow Patterns

Standard Development Flow

  1. Create feature branch
  2. Make changes to files
  3. Check status (git_status)
  4. Review changes (git_diff_unstaged)
  5. Stage changes (git_add)
  6. Review staged changes (git_diff_staged)
  7. Create commit (git_commit)
  8. Review commit (git_show HEAD)

Branch Comparison Flow

  1. Switch to feature branch
  2. Compare with main (git_diff with target: "main")
  3. Review commit history (git_log)
  4. 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