Git configuration#

The git setup loads an OS base config, then a user config, then optional tool configs when the tools are discoverable on that machine.

Directory layout#

Show layout
home/dot_config/git#
$ lsd --almost-all --tree home/dot_config/git
git
├── global.gitignore
├── linux.gitconfig.tmpl
├── no-op.gitconfig
├── symlink_config.tmpl
├── tool-delta.gitconfig
├── tool-kdiff3.gitconfig
├── user-vvnraman.gitconfig
└── windows.gitconfig.tmpl

Load order#

  1. symlink_config.tmpl selects the OS-specific base file.

    symlink_config.tmpl#
    1{{- if eq .chezmoi.os "windows" -}}
    2windows.gitconfig
    3{{- else -}}
    4linux.gitconfig
    5{{- end -}}
    
  2. The OS base file includes user config with a safe fallback to no-op.gitconfig.

    linux.gitconfig.tmpl#
     1# vim: ft=gitconfig
     2{{ $source_git := joinPath .chezmoi.sourceDir "dot_config" "git" -}}
     3{{ $candidate := print "user-" (includeTemplate "user-config.tmpl" .) ".gitconfig" -}}
     4{{ $candidate_tmpl := print $candidate ".tmpl" -}}
     5{{ $paths := includeTemplate "expand-executable-paths.tmpl" . | fromJson -}}
     6[include]
     7{{- if or (stat (joinPath $source_git $candidate)) (stat (joinPath $source_git $candidate_tmpl)) }}
     8    path = ~/.config/git/{{ $candidate }}
     9{{- else }}
    10    path = ~/.config/git/no-op.gitconfig
    
    windows.gitconfig.tmpl#
     1# vim: ft=gitconfig
     2{{ $source_git := joinPath .chezmoi.sourceDir "dot_config" "git" -}}
     3{{ $candidate := print "user-" (includeTemplate "user-config.tmpl" .) ".gitconfig" -}}
     4{{ $candidate_tmpl := print $candidate ".tmpl" -}}
     5{{ $paths := includeTemplate "expand-executable-paths.tmpl" . | fromJson -}}
     6[include]
     7{{- if or (stat (joinPath $source_git $candidate)) (stat (joinPath $source_git $candidate_tmpl)) }}
     8    path = ~/.config/git/{{ $candidate }}
     9{{- else }}
    10    path = ~/.config/git/no-op.gitconfig
    
  3. The OS base file resolves executable search paths and conditionally includes tool snippets. Path data and expansion behavior are documented in Chezmoi data and Chezmoi template helpers.

    linux.gitconfig.tmpl#
    11{{- end }}
    12{{- if findExecutable "delta" $paths }}
    13    path = ~/.config/git/tool-delta.gitconfig
    14{{- end }}
    15{{- if findExecutable "kdiff3" $paths }}
    16    path = ~/.config/git/tool-kdiff3.gitconfig
    
    windows.gitconfig.tmpl#
    11{{- end }}
    12{{- if findExecutable "delta" $paths }}
    13    path = ~/.config/git/tool-delta.gitconfig
    14{{- end }}
    15{{- if findExecutable "kdiff3" $paths }}
    16    path = ~/.config/git/tool-kdiff3.gitconfig
    

See also:

Relevant changelogs#