Cross-platform

Git configuration settings can be stored in three different files: The system configuration file, the global configuration file and the repository's local configuration file. See git on Windows - location of configuration files [1] for their locations.

When you use multiple subsystems on Windows (like MSYS2, Cygwin or any of the the Windows Subsystem for Linux distributions) it can be a chore to keep the git configurations synchronized. In other words: The less configuration files to maintain, the better.

Whether it's git for Windows, or one of the subsystem-specific git binaries:

Each of the git binaries that runs on Windows expands the tilde ( ~ ) to the home directory, and the path separator is always a slash ( / ).

These features can be used in our advantage in order to simplify the git configuration files between all subsystems.

Re-defining the system

The system configuration file is meant to store all system-specific configuration settings, which will be applied to all users and git repositories on the system.

If you're the only user of your workstation, it makes sense to re-define system as subsystem:

All subsystem-dependent git configuration settings should be set in the system git configuration file.

This means that settings depending on underlying binaries, like tools to diff binary files (see Diff binary files like docx, odt and pdf with git [2]) or subsystem-specific files should be configured in the system git configuration file. Examples of such parameters are

http.sslcainfo
http.sslbackend
sendemail.smtpserver
help.format
diff.pdf.textconv

The system configuration has a fixed path, relative to the installation directory: etc/gitconfig . This configuration file can be read using git config --list --system

Global means universal

Any user-specific setting should be set in the global git configuration file.

Global configuration files can be found in what the binary or environment considers the HOME directory (see git on Windows - location of configuration files [1]).

Let's suppose from Window's point of view, the home directory of MSYS2 is U:\ , and that is where the master .gitconfig file resides. By symlinking that file from a command prompt from the Windows home directory ( %USERPROFILE% ) one universal (or global) configuration file can be used - only one that needs to be maintained. From the Windows shell:

mklink %USERPROFILE%\.gitconfig U:\.gitconfig

References to other user dependent files like global gitignore files can be set using the tilde ( ~ ) notation and slash ( / ) path separator. They need to be relative to the home directory.

git config --global --add core.excludesfile ~/.gitignore_global

Of course you still need to symlink the file .gitignore_global from any subsystem, similar to .gitconfig . From Windows:

mklink %USERPROFILE%\.gitignore_global U:\.gitignore_global

The above workflow allows you to maintain a single personal git configuration file. For each new subsystem all you need to do is create the necessary symlinks, and everything is good to go. If you're using Debian on Windows for example, then the command will look something like:

mklink
%USERPROFILE%\AppData\Local\Packages\TheDebianProject.DebianGNULinux_76v4gfsz19hv4\LocalState\rootfs\home\%USERNAME%\.gitconfig
U:\.gitconfig

The exact path depends on the Windows Subsystem for Linux distribution version, and your username.

Note

Symbolic links and the Windows Subsystem for Linux are currently not entirely working: This is scheduled for next release, see Microsoft's GitHub repository [3].

So, if you're the only user of a system:

  • subsystem-dependent settings go in the system configuration file, per subsystem.
  • user-specific settings go in the global configuration file, per user.
  • always use relative paths, using a tilde ( ~ ) and slash ( / )
[1](1, 2) https://www.onwebsecurity.com/configuration/git-on-windows-location-of-global-configuration-file.html
[2]https://www.onwebsecurity.com/configuration/diff-binary-files-docx-odt-pdf-with-git.html
[3]https://github.com/Microsoft/WSL/issues/2995

Comments

comments powered by Disqus