Pages

Monday, February 17, 2020

Using multiple git configurations

It is fairly common that you might be contributing to multiple git repositories which make different git configuration necessary.

Mine and probably the most common case is that I am using different contributor email addresses for my private and work git repositories. You might also want want to have separate global git ignores or other options that differ in multiple repositories.

The way I do it is having one ~/.gitconfig which looks like this:

[user] 
  name = Christof Damian 
  email = christof@damian.net 

[core] 
  excludesfile = ~/.gitignore_global 

[includeIf "gitdir:~/devex/"] 
  path = ~/.gitconfig_devex 

This defines the defaults for my name, email and a global gitignore. It also tell git to look at another git config for all repositories that are below the ~/devex/ folder. This file is very short for me, as it just changes the email address (~/.gitconfig_devex):

[user] 
  email = christof.damian@devex.com 

The ~/.gitignore_global is just a normal gitignore file, which excludes all the files the editors or tools I use create. It could for example look like this:

*~ 
/.project 
# whatever files your local editor/tools config generates

You could use for example https://www.gitignore.io/ to generate this

No comments:

Post a Comment