git-mcp
MCP (Model Context Protocol) server for interacting with Git using natural language. This tool allows you to perform common Git operations through simple commands, and it will figure out the right Git commands to execute.
Installation
pnpm install
pnpm build
Usage
Add to Claude Code
pnpm run mcp:add
Available Tools
Undo Operations
git_undo_commit | Undo the last commit while keeping changes | "How do I undo my last commit?" | git reset --soft HEAD~1 |
git_revert | Revert commits by creating new commits | "How do I revert the last 3 commits?" | git revert HEAD~3..HEAD |
git_discard_changes | Discard local changes | "How do I discard all my local changes?" | git clean -fd && git checkout -- . |
git_unstage | Unstage files from staging area | "How do I unstage a file I accidentally added?" | git reset HEAD <file> |
git_undo_merge | Abort an in-progress merge | "How do I undo a merge?" | git merge --abort |
git_reset | Reset to a specific commit | "How do I reset to a previous commit?" | git reset --<mode> <commit> |
Commit Editing
git_squash | Squash multiple commits into one | "How do I squash my last N commits into one?" | git reset --soft HEAD~N && git commit |
git_amend | Amend the last commit | "How do I edit an old commit message?" | git commit --amend |
git_stage | Stage files for commit | "How do I add files to staging?" | git add <files> |
git_commit | Create a new commit | "How do I commit my changes?" | git commit -m "<message>" |
Branching & Merging
git_create_branch | Create a new branch | "How do I create a branch from an old commit?" | git checkout -b <branch> <ref> |
git_list_branches | List all branches | "What branches exist?" | git branch -a -vv |
git_checkout | Switch to a branch | "How do I switch branches?" | git checkout <branch> |
git_delete_branch | Delete a branch | "How do I delete a branch?" | git branch -d <branch> |
git_move_changes | Move changes to new branch | "How do I move my changes to a different branch?" | git stash && git checkout -b <branch> && git stash pop |
git_cherry_pick | Apply commits from another branch | "How do I cherry-pick a commit?" | git cherry-pick <commit> |
git_merge | Merge a branch | "How do I merge without a merge commit?" | git merge [--no-ff/--squash] <branch> |
git_rebase | Rebase current branch | "How do I reorder my commits?" | git rebase <target> |
Syncing & Remote
git_pull | Pull changes from remote | "How do I pull without creating a merge commit?" | git pull --rebase |
git_push | Push commits to remote | "How do I force push safely?" | git push --force-with-lease |
git_fetch | Fetch from all remotes | "How do I update remote refs?" | git fetch --all --prune |
git_update_branch | Update branch with main | "How do I update my branch with latest from main?" | git fetch && git rebase origin/main |
git_stash | Stash/restore changes | "How do I save my work temporarily?" | git stash [pop/list/drop] |
git_remote | Manage remotes | "How do I add a remote?" | git remote add/remove |
History Inspection
git_log | Show commit history | "Show me recent commits" | git log |
git_show | Show commit details | "How do I see what changed in a commit?" | git show <commit> |
git_blame | Show who changed each line | "How do I find who changed a specific line?" | git blame <file> |
git_diff | Show differences | "Show me the changes" | git diff [--staged] |
git_search | Search commits | "How do I find a commit by its message?" | git log --grep/S/author |
git_file_history | Show file history | "How do I see the history of a specific file?" | git log --follow -- <file> |
git_status | Show working tree status | "What's my current status?" | git status |
Recovery
git_reflog | Show reference log | "How do I find lost commits?" | git reflog |
git_recover_commit | Recover a lost commit | "How do I get back a commit I reset?" | git cherry-pick/checkout <commit> |
git_recover_branch | Recover deleted branch | "How do I recover a deleted branch?" | git checkout -b <branch> <reflog-commit> |
git_find_lost | Find dangling commits | "Find unreachable commits" | git fsck --unreachable |
git_reset_to_reflog | Reset to reflog entry | "Restore to previous state" | git reset HEAD@{n} |
Example Queries
Here are some natural language queries and the tools that handle them:
- "Undo my last commit" →
git_undo_commit
- "Revert the last 3 commits" →
git_revert with count=3
- "Discard all my local changes" →
git_discard_changes
- "Unstage the file I just added" →
git_unstage
- "Squash my last 5 commits" →
git_squash with count=5
- "Create a branch from commit abc123" →
git_create_branch with fromRef="abc123"
- "Move my uncommitted changes to a new branch" →
git_move_changes
- "Cherry-pick commit xyz789" →
git_cherry_pick
- "Update my branch with the latest from main" →
git_update_branch
- "Who changed line 42 in app.js?" →
git_blame with file and line range
- "Find the commit that added 'TODO'" →
git_search with type="content"
- "Recover my deleted feature branch" →
git_recover_branch
License
MIT