gitgit-config

Platform-specific git configuration files


I have three git configuration files. One is named .gitconfig and contains 90% of my git settings. Common, platform-agnostic settings go here. The other is named .gitconfig-windows and contains Windows-only settings for Git (Notepad++ as my editor, for example, which won't exist on Linux). I also have a .gitconfig-linux for the Linux platform, obviously.

Right now I have the following at the top of my .gitconfig file:

[include]
    path = .gitconfig-windows

Since I'm currently working out of windows, this means my .gitconfig will include all of the settings from .gitconfig-windows. When I'm on Linux, I have to edit my .gitconfig file to point to the .gitconfig-linux file instead. It's pretty tedious to have to edit my .gitconfig each time I switch platforms. I have all 3 of my config files in Dropbox for easy syncing between all of my work machines (mixture of Windows and Ubuntu environments). Any recommendations on how to more easily setup Git to use platform-specific settings on only those platforms?


Solution

  • You could rename your current .gitconfig file to something like .gitconfig-common, and change the platform-specific files to include it (instead of the other way around). Then, on each machine where you work, create a .gitconfig file outside of Dropbox that does nothing but include the appropriate platform-specific file in your Dropbox.

    So on Windows, for example, you'd have .gitconfig include .gitconfig-windows, which includes .gitconfig-common. The .gitconfig file contains nothing but a platform-specific include directive so there's no need to synchronize it with Dropbox.