(Git v2.13+) Easily Use Work & Personal Git Accounts On The Same Computer

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@golgaroth·
0.000 HBD
(Git v2.13+) Easily Use Work & Personal Git Accounts On The Same Computer
![octobiwan.jpg](https://steemitimages.com/DQme2MysXK9tQD2JUTadfL6xuUDBB5BKWsN8W8hDoMfDCcv/octobiwan.jpg)

# Using 2+ git accounts on the same computer

Do you use a personal git account on your home computer, but also want to occasionally use it to make some commits to your work git repos?

The easiest solution I've found goes like this:

Make sure you're using git version 2.13 or newer.

Let's say your current ```.gitconfig``` file is located at ```~/.gitconfig``` and it looks like this:

```
[user]
  email = catwarrior01@aohell.com
  name = "Teh OSS Kitteh W4rrior"
[alias]
  co = checkout
```

That's cool. But you've just been hired by google and now you'd like to use your real name and google email when authoring commits when you're working from home and sipping on a pina colada.

Git v2.13 gives us the option of using conditional configuration includes. This lets us apply settings from a specific .gitconfig to a directory (and all its subdirectories).

Here's how it works:

Let's update our ```~/.gitconfig``` to look like this:

```
[includeIf "gitdir:~/source/personal/"]
  path = ~/.gitconfig-personal
[includeIf "gitdir:~/source/work/"]
  path = ~/.gitconfig-work
```

This tells git to pay attention to the directory we're currently in when we issue git commands.

If the directory we're currently in starts with ```~/source/personal```, it will use the config file ```~/.gitconfig-personal``` for all its configuration.

Likewise, if the current directory we're in starts with ```~/source/work```, it will use the config file ```~/.gitconfig-work``` for all its configuration.

Now let's create this ```~/.gitconfig-personal``` file. It should look like this:

```
[user]
  email = catwarrior01@aohell.com
  name = "Teh OSS Kitteh W4rrior"
[alias]
  co = checkout
```

And let's create the ```~/.gitconfig-work``` file. It should look like this:

```
[user]
  email = leeroyjenkins@google.com
  name = "Leeroy  A. Jenkins"
[alias]
  co = checkout
```

Tada! You're done.

Now your commits will be tagged with the appropriate name and email address depending on whether the repo you're working in is inside of the personal or work directories on your home computer.

For pulling down your work repos, I'd suggest just using https instead of ssh as it will be easier than managing multiple ssh keys.

Hope this helped!

If you enjoyed this article, please upvote and resteem! Thanks!
👍 , , , ,