Recently Git added an amazingly needed feature, include for gitconfig files.
This means that you can split your gitconfig configurations across multiple files, e.g. you can have a .gitconfig file for your nonsensitive information and a git ignored .githubconfig file containing your private github token.
Storing GitHub tokens doesn’t seem to be all that uncommon, so hopefully with Git’s include feature this will change.
This what you’ll have in your .gitconfig file:
And in your .githubconfig file:
Then in your .gitignore file have:
As an aside, to include multiple config files the directive is the same:
The path can be either relative from the gitconfig file or absolute.
If you’ve been silly enough to have put sensitive information into your gitconfig on the assumption it wouldn’t come back at you, now Git has the functionality so use it!
Read this page on how to purge a file from your history.
Purge your gitconfig file from your history (below), put the sensitive information into another file that you’ve git ignored, include that file in your gitconfig and add your newly desensitized gitconfig back under version control.
Git’s include will be in version 1.7.10, but if you don’t want to wait homebrewers will soon be able to easily install Git’s latest development version via:
brew install git --HEAD
Or just git the repo and build it yourself:
git clone git://github.com/gitster/git.git