Is it possible to include a file in your .gitconfig
Git (1.7.10+) now supports this syntax in
[include] path = /path/to/file
See here for a detailed description of the git change and its edge cases.
By the way, a couple of subtleties worth pointing out:
Environment-variable expansion, e.g.
$HOME, is not supported. (Expansion of
~appeared in Git 184.108.40.206.)
If a relative path is specified, then it is relative to the .gitconfig file that has the
[include]statement. This works correctly even across chained includes -- e.g.
[include] path = subdir/gitconfig
[include] path = nested_subdir/gitconfig
... which will cause
subdir/nested_subdir/gitconfigto be loaded.
If git can't find the target file, it silently ignores the error. This appears to be by design.
You may load it from the command-line:
$ git config --local include.path "/path/to/.gitconfig"
"$PWD"/.gitconfig instead, if you want to load the file from the current directory.
After running above command, the following lines are added into your
[include] path = /path/to/.gitconfig
See Mike Morearty's answer:
You can include one config file from another by setting the special
include.pathvariable to the name of the file to be included.
The included file is expanded immediately, as if its contents had been found at the location of the include directive.
If the value of the
include.pathvariable is a relative path, the path is considered to be relative to the configuration file in which the include directive was found.
The value of
include.pathis subject to tilde expansion:
~/is expanded to the value of
~user/to the specified user's home directory.
I do not think so.
I would rather put that setting in the
User-specific configuration file. Also called "global" configuration file.
That way, it completes the .gitconfig project-specific file, without being published when pushed to GitHub. See also this SO answer for more on the global config file.
Git has 3 config files.
bjeanes adds in the comments:
it looks like everyone missed the point of this question.
David obviously wants to push up a repo of all his dot files (
gemrc, etc.) INCLUDING his
.gitconfigso he can have all his settings on all his machines.
A way to push parts of a
.gitconfigfile by including and ignoring private entries is what he (and I, for that matter) is after.
A possible way would be to use a smudge/clean filter driver to decrypt/encrypt one file with private sensitive informations (see this thread), in order to complete a local file like ~/.gitconfig with the decrypted parts that are relevant to that file.
That way you can have a Git repo with all your dot files, plus one file with encrypted information meant to be decrypted and added to said dot files.
myPrivateInfosFile filter=gpg diff=gpg
In your repo .config file:
[filter "gpg"] smudge = gpg -d -q --batch --no-tty clean = gpg -ea -q --batch --no-tty -r C920A124 [diff "gpg"] textconv = decrypt
(a GPG-based solution means, off course, you have communicated your private/public keys by another mean onto the destination computer where you want to restore all your dot files by cloning this special repo)
Actually, in your case, the smudge script needs to be completed as it must, after decrypted that file, go on and add relevant parts to your global
~/.gitconfig file (unless you overwrite the global config file with another location) or other dot files for that matter.
https://kerneltrap.org/mailarchive/git/2008/3/13/1153274/thread (gpg inconveniences are discussed further in this thread) (this is different than having a full encrytped Git repo, as discussed here)