Logo
BlogDashboardAboutProjects
Logo
HomeBlogDashboardAboutProjects
GithubGithub
LinkedinLinkedin
TwitterTwitter
v1.12.1
26 Dec 2022
·
1 min read

Different Git identities for personal and work projects

I kept committing with my personal email on work projects. Git's includeIf directive fixes this by loading a different config based on which directory you're in. No manual switching.

I personally came across a situation where I used a default email address for my commits for any projects. However, I want to use a different email address whose custom domain name belongs to an organisation. With the default settings, and while creating new directories, I tend to forget to change the git config before committing any changes. This can be particularly frustrating, especially after multiple commits and having pushed to the remote repository.

Since Git v2.13, they have added the conditional includes feature. This allowed us to set the git config for specific conditions.

Take for example the directories setup.

Any projects: $HOME/projects Organisation's projects: $HOME/projects/organisation

[user]
  email = john.doe@personal.dev
  name = John Doe
  signingkey = SomeSigningKey
[commit]
  gpgSign = true
[includeIf "gitdir:~/projects/organisation/"]
  path = ~/.organisation.gitconfig

So what this does is to set a default global configuration and the includeIf will set the specific configuration for the organisation for the particular directory. This will also work for any subdirectories too.

Hope this helps anyone who came across similar situations and were looking for a seamless solution to this.

Related Articles

24 Oct 2025
3 tags
How I use GitHub CLI day-to-day
I keep most of my work inside the terminal. Here's how I use gh to create repos, track issues, and merge pull requests without touching the GitHub website.
26 Feb 2023
2 tags
Setting 'main' as your default Git branch
GitHub switched the default branch name from master to main in 2020. One line in your global git config means you never have to set it manually on a new repo again.
21 Apr 2026
2 tags
Per-project shell environments with direnv
Loading the right environment variables when I cd into a project used to mean sourcing .env files by hand or leaking secrets into my global shell. direnv fixes both by loading a per-directory shell environment, and unloading it the moment I leave.
29 Mar 2023
1 tag
Feature flags: ship code without shipping features
A feature flag is an if/else around a piece of code, controlled by an environment variable. It lets you merge and deploy work-in-progress without turning it on. Fewer conflicts, safer releases.