Sourcing external files from your .gitconfig

Josh Sherman
1 min read
Software Development Version Control

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.

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

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.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles