git-mcp Tutorial: Setup Multiple Git Profiles Easily
Tired of mixing up your work and personal Git identities? This step-by-step git-mcp tutorial shows you how to easily set up and manage multiple Git profiles.
Alex Grayson
A DevOps engineer and open-source enthusiast passionate about simplifying developer workflows.
Ever had that sinking feeling right after a `git push`? You check the commit log on GitHub and there it is: your personal email and silly avatar attached to a commit in your company’s most important repository. Or maybe it's the other way around, with your formal work identity plastered all over your fun weekend project. It’s a classic developer blunder.
Juggling work, personal, and open-source projects on the same machine often means a constant, tedious dance with your Git configuration. But what if you could switch your Git identity with a single, simple command? That's exactly what `git-mcp` is for. In this tutorial, we'll show you how this lightweight tool can save you from future identity crises and streamline your workflow.
Why Managing Multiple Git Identities is a Headache
In a perfect world, we'd have separate machines for everything. But in reality, our development machine is a hub for all our coding endeavors. This creates a conflict for Git, which relies on a global configuration file (`~/.gitconfig`) to identify you. By default, every commit you make on your machine uses the `user.name` and `user.email` set in that file.
The consequences of mixing these identities can range from mildly embarrassing to genuinely problematic:
- Lack of Professionalism: Committing to a corporate repo with `slayer_of_code_99` doesn't exactly scream "senior engineer."
- Privacy Leaks: Exposing your personal email address in public open-source projects or your work email in personal ones can lead to unwanted contact.
- Broken Workflows: Many companies use commit email addresses to link to internal tools like Jira or to enforce GPG commit signing. A wrong email means broken integrations and failed CI/CD checks.
Manually changing your identity for each project is tedious and, more importantly, easy to forget. There has to be a better way.
The Old Ways: Manual Configs and `includeIf`
Before we jump into `git-mcp`, let's look at the two most common ways developers handle this problem today.
The Manual `git config` Dance
The most straightforward approach is to override the global config on a per-repository basis. After you `git clone` a new project, you run:
git config --local user.name "Your Name"
git config --local user.email "your.email@example.com"
This works, but its biggest flaw is that you have to remember to do it for every single new repository. Forget just once, and you're back to square one. It's a fragile system that relies entirely on human discipline.
A Better Way: Git's `includeIf`
Since Git 2.13, a much more robust, native solution has been available: conditional includes. You can tell your global `~/.gitconfig` to include another config file only if the repository is in a specific directory.
For example, you could structure your projects like this:
~/dev/
├── work/
│ └── project-a
└── personal/
└── fun-project-b
Then, you would edit your `~/.gitconfig` to look something like this:
[user]
name = Your Personal Name
email = personal@email.com
[includeIf "gitdir:~/dev/work/"]
path = ~/.gitconfig-work
And in `~/.gitconfig-work`, you'd have:
[user]
name = Your Work Name
email = work@email.com
This is powerful and effective! Any repo inside `~/dev/work/` will automatically use your work identity. So, why isn't everyone doing this? It can feel a bit abstract to set up, requires disciplined folder organization, and editing config files directly isn't everyone's cup of tea. It's a fantastic solution for power users, but it can feel like overkill for those wanting something simpler.
Enter git-mcp: Your Git Profile Switchboard
`git-mcp` (Multiple Config Profiles) is a simple shell script that acts as a user-friendly layer on top of Git's configuration system. It doesn't try to reinvent the wheel; it just makes managing local repository configurations foolproof and fast.
Its philosophy is simple:
- Define your profiles once: Create profiles for "work," "personal," "opensource," etc., with their respective names, emails, and GPG signing keys.
- Set the profile for a repo once: Navigate into a repository and assign one of your predefined profiles to it.
- Forget about it forever: `git-mcp` handles the local `git config` for you. Every future commit in that repo will use the correct identity.
It strikes a perfect balance between the fragility of the manual method and the setup complexity of `includeIf`.
Step-by-Step Tutorial: Setting Up git-mcp
Let's get `git-mcp` installed and configured. It only takes a few minutes.
Step 1: Installation
`git-mcp` is designed to be a simple script you can place in your path. We'll download it and make it executable.
# Download the script (ensure you trust the source)
sudo curl -L https://raw.githubusercontent.com/jules-ch/git-mcp/master/git-mcp -o /usr/local/bin/git-mcp
# Make it executable
sudo chmod +x /usr/local/bin/git-mcp
Now you can run `git mcp` as if it were a native Git command. Verify the installation by running:
git mcp --version
Step 2: Creating Your Profiles
Next, let's define the identities you want to switch between. The command is `git mcp add
Let's create a "work" profile:
$ git mcp add work
✓ What is the user name for the 'work' profile? · Alex Grayson
✓ What is the user email for the 'work' profile? · alex.grayson@company.com
✓ What is the GPG signing key for the 'work' profile? (optional) ·
✓ Successfully added the 'work' profile!
Now, let's add a "personal" profile. This time, we'll include a GPG key for signed commits on our personal projects.
$ git mcp add personal
✓ What is the user name for the 'personal' profile? · Alex G.
✓ What is the user email for the 'personal' profile? · a.grayson.dev@email.com
✓ What is the GPG signing key for the 'personal' profile? (optional) · 1234ABCD5678EFGH
✓ Successfully added the 'personal' profile!
These profiles are now saved globally by `git-mcp`.
Step 3: Using Your Profiles in Repositories
This is where the magic happens. Navigate to any Git repository and tell `git-mcp` which profile to use.
For your company's project:
cd ~/dev/work/project-a
git mcp set work
This command does one simple thing: it writes the name, email, and signing key from your "work" profile into the repository's local `.git/config` file. It's the same as running `git config --local` manually, but without the risk of typos and with the convenience of a predefined profile.
For your personal project:
cd ~/dev/personal/fun-project-b
git mcp set personal
That's it! From now on, any commit you make in `project-a` will use your work identity, and any commit in `fun-project-b` will use your personal one. No more manual configuration, and no need to worry about your directory structure.
Step 4: Managing Your Profiles
`git-mcp` comes with a few handy commands to manage your profiles:
- List all profiles: `git mcp ls`
- Remove a profile: `git mcp rm personal`
- See which profile is active: `git mcp status` (when inside a repository)
git-mcp vs. Other Methods: A Quick Comparison
To help you decide what's right for you, here’s a breakdown of the different approaches:
Method | Ease of Use | Setup Complexity | Flexibility | Best For |
---|---|---|---|---|
Manual `git config --local` | Low | None | High | One-off overrides, not for systematic use. |
Git `includeIf` | Medium | Medium | Very High | Power users who want a native, directory-based solution and don't mind editing config files. |
`git-mcp` | High | Low | Medium | Developers who want a simple, explicit, and error-proof way to manage profiles on a per-repo basis. |
Final Thoughts: Peace of Mind for Your Commits
The problem of managing multiple Git identities is a common annoyance that can have real consequences. While Git's native `includeIf` feature is a powerful solution for those who love organized directories and editing config files, `git-mcp` offers a compelling alternative focused on simplicity and ease of use.
Here's when `git-mcp` shines:
- You want a tool with a very low learning curve.
- You prefer to explicitly set an identity for a repository rather than relying on its location on your filesystem.
- Your project folders aren't neatly organized by context (work, personal, etc.).
- You want a fire-and-forget solution that just works.
By investing a few minutes to set up `git-mcp`, you can eliminate a recurring source of developer anxiety. Stop double-checking your `git config` before every commit and get back to what you do best: building amazing things.