---
title: "How to Use Multiple Git Configs on One Computer"
description: "We configure Git so that we can edit our project with different credentials."
pubDate: "Aug 01 2024"
heroImage: "/multiple-git-configs.png"
---

If you work on different projects with your computer, it may be necessary to use different credentials. There is a simple solution for this by customizing the .gitconfig and creating different git profiles.

To make this work, we organize our projects into different folders. Since I use [ghq](https://github.com/x-motemen/ghq) to clone my projects, we will use this structure to customize our Git config.

![Screenshot of a console output that shows multiple folders](/multiple-git-configs-01.png)

Let's assume that we have 3 different folders. In this case the following:

- git.hashdot.co
- github.com
- ssh.dev.azure.com

All subfolders then use our created configs. Let's start creating them.

First we create a global Git config in our home directory:

```bash
touch ~/.gitconfig
```

Then we add the following content:

```bash
[includeIf "gitdir:~/git.hashdot.co/"]
  path = ~/.gitconfig-personal
[includeIf "gitdir:~/ssh.dev.azure.com/"]
  path = ~/.gitconfig-work
```

Now we need to create the two configs as follows:

```bash
touch ~/.gitconfig-personal

touch ~/.gitconfig-work
```

In the personal config we add the following content:

```bash
[user]
  name = Your Name
  email = Your personal email
```

In the work config we add the following content:

```bash
[user]
  name = Your Name
  email = Your work email
```

To test that it works, we can go to any subdirectory and execute the following command:

```bash
git config --list
```

Now something like the following should appear:

```bash
core.editor=nvim
includeif.gitdir:~/ghq/git.hashdot.co/.path=~/.gitconfig-personal
user.name=Lars Hampe
user.email=hello@hashdot.co
includeif.gitdir:~/ghq/ssh.dev.azure.com/.path=~/.gitconfig-work
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
submodule.active=.
remote.origin.url=https://git.hashdot.co/HashDot/website.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
```
