Bas Bossink Bas Bossink - 10 days ago 8
Git Question

Best practices for cross platform git config?

Context



A number of my application user configuration files are kept in a git repository for easy sharing across multiple machines and multiple platforms. Amongst these configuration files is
.gitconfig
which contains the following settings for handling the carriage return linefeed characters

[core]
autocrlf = true
safecrlf = false


Problem



These settings also gets applied on a GNU/Linux platform which causes obscure errors.

Question



What are some best practices for handling these platform specific differences in configuration files?

Proposed solution



I realize this problem could be solved by having a branch for each platform and keeping the common stuff in master and merging with the platform branch when master moves forward. I'm wondering if there are any easier solutions to this problem?

Answer

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

The conclusion was:

*.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.