Manage Multiple Git Accounts? A git-mcp Implementation Guide
Tired of juggling multiple Git accounts for work and personal projects? This guide shows you how to use git-mcp to easily manage different profiles and SSH keys.
Alex Rivera
A DevOps engineer and technical writer passionate about streamlining developer workflows.
If you're a developer juggling a day job and personal projects, you've likely felt the pain. You clone a work repository, make some commits, and then realize—drat—you just pushed code with your personal GitHub email and username. Or the other way around. It's a dance of `git config` commands, multiple SSH keys, and constant low-grade anxiety about mixing your digital identities.
While there are several ways to tackle this, from complex SSH config files to Git's `includeIf` directive, they often feel like patching a leaky boat. Today, I'm going to introduce you to a simple, elegant, and incredibly effective tool that has completely streamlined my workflow: git-mcp.
This guide will walk you through exactly what git-mcp is, why it's a game-changer, and how you can set it up in just a few minutes.
What is git-mcp and Why Use It?
git-mcp stands for "Git Multiple Configuration Profiles." It's a lightweight, shell-based utility that allows you to define and switch between different Git configurations on the fly. Think of it as a profile manager specifically for Git.
Instead of having one global `~/.gitconfig` file that you're constantly fighting with, git-mcp lets you create isolated profiles. For instance, you can have a 'work' profile with your corporate email and SSH key, and a 'personal' profile with your personal GitHub info.
Here’s why it’s so effective:
- Simplicity: No more editing complex SSH configuration files. You create simple, human-readable profile files.
- Clarity: A quick command, `git mcp current`, instantly tells you which profile is active, either globally or for the specific repository you're in.
- Total Isolation: Each profile manages its own `user.name`, `user.email`, and, most importantly, the specific SSH key to use for authentication.
- Global & Local Control: You can set a default global profile (e.g., 'personal') and then override it on a per-project basis (e.g., set 'work' for your company's monorepo).
Prerequisites
Before we dive in, make sure you have the following ready:
- Git: It's a guide about Git, so this one's a given!
- Command-Line Familiarity: You should be comfortable running commands in your terminal.
- Separate SSH Keys: You need to have already generated unique SSH keys for each account you want to manage. If you haven't, you can do so easily. For example:
# For your personal account ssh-keygen -t ed25519 -C "your_personal@email.com" -f ~/.ssh/id_ed25519_personal # For your work account ssh-keygen -t ed25519 -C "your_work@company.com" -f ~/.ssh/id_ed25519_work
Remember to add the corresponding public keys (`.pub` files) to your GitHub, GitLab, or Bitbucket accounts.
Step-by-Step Implementation Guide
Let's get git-mcp up and running. The process is straightforward and should only take about 5-10 minutes.
Step 1: Installing git-mcp
First, we'll clone the git-mcp repository into a hidden directory in your home folder.
git clone https://github.com/sivaprasadreddy/git-mcp.git ~/.git-mcp
Next, you need to "source" the script so that the `git mcp` command is available in your shell. Open your shell's configuration file (e.g., `~/.zshrc` for Zsh or `~/.bashrc` for Bash) and add the following line to the end:
source ~/.git-mcp/git-mcp.bash
To apply the changes, either restart your terminal or run `source ~/.zshrc` (or `source ~/.bashrc`).
Step 2: Configuring Your Profiles
This is where the magic happens. All your profiles live as simple text files inside the `~/.git-mcp/profiles/` directory. Let's create two profiles: `personal` and `work`.
Create the 'personal' profile:
# Create and open the file in your preferred editor (e.g., nano, vim, VS Code)
nano ~/.git-mcp/profiles/personal
Add the following content, replacing the placeholder values with your own information:
# ~/.git-mcp/profiles/personal
USER_NAME="Your Personal Name"
USER_EMAIL="your_personal@email.com"
SSH_KEY_PATH="~/.ssh/id_ed25519_personal"
Create the 'work' profile:
nano ~/.git-mcp/profiles/work
Add your work-specific information:
# ~/.git-mcp/profiles/work
USER_NAME="Your Work Name"
USER_EMAIL="your_work@company.com"
SSH_KEY_PATH="~/.ssh/id_ed25519_work"
Important: Make sure the `SSH_KEY_PATH` points to the private key file and that the path is correct. Using `~` for your home directory works perfectly.
Step 3: Using git-mcp
With your profiles configured, you can now manage them with a few simple commands.
- List available profiles:
git mcp list
This will show you `personal` and `work`.
- Set a global profile:
git mcp use personal
This sets your global Git configuration. Any new repository you initialize or clone will use the 'personal' profile by default. I recommend setting your most-used profile as the global default.
- Check the current profile:
git mcp current
This will tell you which profile is currently active.
- Set a local (per-repository) profile:
This is the most powerful feature. Navigate into a specific project directory and set a profile just for that folder.
cd ~/Projects/my-work-repo git mcp use work --local
Now, any Git command you run inside `my-work-repo` will use the 'work' profile, overriding your global 'personal' setting. This is exactly the isolation we need!
A Practical Workflow Example
Let's see how this works in a real-world scenario.
- Set your global default. You do most of your side-projects on your personal account, so let's make that the default.
git mcp use personal
- Clone a work repository.
git clone git@github.com:company/project-x.git cd project-x
- Set the local profile for this repository. Before you do anything else, you tell git-mcp that this is a work project.
git mcp use work --local
- Verify the configuration.
# Inside ~/project-x git config user.email # Output: your_work@company.com # Now, navigate to a different directory cd ~ git config user.email # Output: your_personal@email.com
As you can see, the configuration is context-aware. You no longer have to think about it. Just set the local profile once when you clone a repo, and you're good to go.
Troubleshooting and Tips
- `git: 'mcp' is not a git command.`: This means your shell hasn't sourced the script properly. Double-check that the `source ~/.git-mcp/git-mcp.bash` line is in your `.zshrc` or `.bashrc` file and that you've restarted your terminal.
- `Permission denied (publickey)` errors: This is almost always an SSH key issue, not a git-mcp issue. Verify two things: 1) The `SSH_KEY_PATH` in your profile file is 100% correct. 2) The corresponding public key (`.pub` file) has been added to the correct account on GitHub/GitLab.
- Tip: Use descriptive profile names if you have more than two accounts, like `github-personal`, `gitlab-work`, `bitbucket-freelance`.
Conclusion
Juggling multiple Git identities doesn't have to be a source of friction in your development process. By investing a few minutes to set up git-mcp, you can create a robust, clear, and context-aware system that lets you focus on what actually matters: writing code.
It removes the mental overhead of managing users and keys, giving you the confidence that you're always committing with the right identity. Give it a try—I'm confident it will become an indispensable part of your toolkit.