text if condition and inside the brackets there is a git icon

Automatically Using Different Author for Different Git Directories

Published on:

Yes, it’s possible. The answer is git conditional configs.

Problem

I still go to school. Our school has it’s own GitLab instance in which sometimes we have to work in. I mainly use GitHub so my global git configuration contained my user name and email for my GitHub account. If I had to work with one of the school GitLab’s repositories then I always had to manually set the author details.

I saw the solution to this problem in a YouTube video named So You Think You Know Git: conditional configs.

Solution

In the video he describes the conditional configs and it is really easy to understand. If you can, I also recommend you to watch the whole presentation.

You can the documentation about includeIf. I think it’s pretty self-explanatory.

Here is what I use to solve my problem described above (also see how I use SSH and URL based repo paths next to each other):

[includeIf "hasconfig:remote.*.url:git@github.com:**/**"]
    path = .gitconfig-github

[includeIf "hasconfig:remote.*.url:http://gitlab.myshool.com/**/**"]
    path = .gitconfig-school

In my github, and school config I define the name and email for that author. For example:

[user]
    name = 11Firefox11
    email = 65167877+11Firefox11@users.noreply.github.com

Read more

6 notifications with different volume icons and different volume values with progressbars

Automatic Visual Feedback for System Volume Change in I3wm via Dunst

a laptop in the middle of the forest

I Am Back with some Tips and a New Series