Search code examples
gitconfiguration

Git - add local config file


I wish to check in changes that I have made to my local GIT config file and when I tried this command:

git add .git/config --force

It errors out with the following message:

warning: LF will be replaced by CRLF in .git/config.
The file will have its original line endings in your working directory
error: invalid path '.git/config'
error: unable to add '.git/config' to index
fatal: adding files failed

Wondering if this is possible, or if this is considered bad practice. Note: What I am trying to do is check some default diff tools that the entire team needs to use. If this is considered bad practices, how do I go about accomplishing this? (Other settings I might wish to standardize: whitespace, auto conversion of crlf, etc).


Solution

  • You cannot add files located under .git/
    .git/config also contains local information, such as the list of remote tracking branches, or the list of remotes (possibly with your credentials) which you defined locally, and it does not make much sense to share these.

    Close enough : you can commit a common config file in your repo, and set up each clone with an include directive to include this file :

    # relative path are relative to the .git/ directory :
    git config include.path ../common_config
    

    Link to docs : includes and conditional includes