Sourcing external files from your .gitconfig

If you’re like me, there’s a great chance that you have not only some public
dotfiles but you also have some private stuff you don’t want the
world to have open access to. I refer to these private dotfiles simple as
dotprivate.

I include my dotprivate files as a submodule within my dotfiles. Where things
get tricky is when I want to have a single file that has some public things and
some private things.

One such scenario is my .gitconfig. I have things like colors and editor
settings and such that I don’t mind being shared. Then I have things like my
GitHub email address that I’d prefer to keep private.

Fortunately, git allows you to include files from within your main
.gitconfig file. All you need to do is define an [include] section and a
path that maps to your separate file. You can even have path defined
multiple times!

[include]
  path = /path/to/my/other/gitconfig
  path = /path/to/some/other/gitconfig

Please note that this is only applicable to git 1.7.10 or above.

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.