Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created June 1, 2025 23:08
Show Gist options
  • Save DavidWells/cc1b1f78ebb88c5a3c9c4816a38e58dc to your computer and use it in GitHub Desktop.
Save DavidWells/cc1b1f78ebb88c5a3c9c4816a38e58dc to your computer and use it in GitHub Desktop.
Conditional git user config example

It's possible to conditionally extend the git configuration based on where your repository is located in your file system. That means we can have a global git configuration with all the default configuration and then in a few overrides for all repositories within, for example, the ~/code/work/ folder by adding a little something like this to the ~/.gitconfig file.

via https://dev.to/tastefulelk/conditional-git-profile-configuration-212b

// ~/.gitconfig
[user]
    name = Sebastian Bille
    email = [email protected]

[includeIf "gitdir:~/code/work/"]
    path = ~/code/work/.gitconfig
// ~/code/work/.gitconfig
[user]
    email = [email protected]

Now all repositories inside of the ~/code/work/ folder will use your overridden email but all others will keep using the default configuration.

This could of course be used to override or add any other configuration conditionally as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment