Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for cross platform git config?

Tags:

git

git-config

People also ask

How do I apply a configuration across the entire git environment?

Git stores all global configurations in . gitconfig file, which is located in your home directory. To set these configuration values as global, add the --global option, and if you omit --global option, then your configurations are specific for the current Git repository. You can also set up system wide configuration.

How do I know which git config to use?

You can force Git to read from and write to this file with the --local option. You can find this config file in the . git directory of whatever repository you're currently using. Anyone can view/edit these configuration settings.

What is the purpose of git config?

git config is a powerful command in Git. You can use the Git configuration file to customize how Git works. This file exists in the project level where Git is initialized ( /project/. git/config ) or at the root level ( ~/.

What is git config core Autocrlf?

The git config core. autocrlf command is used to change how Git handles line endings. It takes a single argument. On macOS, you simply pass input to the configuration. For example: $ git config --global core.autocrlf input # Configure Git to ensure line endings in files you checkout are correct for macOS.


Never turn autocrlf on, it causes nothing but headaches and sorrows.

There's no excuse to use \r\n on windows, all decent editors (by definition) can handle \n.


I have reviewed that kind of config setting (crlf) extensively in the question:
distributing git configuration with the code.

The conclusion was:

  • checkout/checking .gitattributes files
  • list all types which explicitly need that kind of conversion.
    For instance:
*.java +crlf
*.txt +crlf
...
  • avoid doing any kind of conversion of type of files which don't need it, because of the various side-effect of such a conversion on merges, git status, shell environment and svn import (see "distributing git configuration with the code" for links and references).
  • avoid any crlf conversion altogether if you can.

Now, regarding the specific issue of per-platform settings, branch is not always the right tool, especially for non-program related data (i.e; those settings are not related to what you are developing, only to the VCS storing the history of your development)

As stated in the question Git: How to maintain two branches of a project and merge only shared data?:

your life will be vastly simpler if you put the system-dependent code in different directories and deal with the cross-platform dependencies in the build system (Makefiles or whatever you use).

In this case, while branches could be use for system-dependent code, I would recommend directory for support tools system-dependent settings, with a script able to build the appropriate .gitattributes file to apply the right setting depending on the repo deployment platform.