I wanted to do the same. The best I could find was @MicTech's solution. However, as @MotoWilliams points out, this does not withstand any updates made by Git in the .gitconfig file, which replaces the link with a new file containing only the new settings.
I solved this by writing the following PowerShell script and running it in my startup profile script. Each time it starts, it copies all the parameters that have been added to the .gitconfig user to the global one, and then replaces all the text in the .gitconfig file with the [include] header, which imports the global file.
I save the global .gitconfig file to the repo along with many other global scripts and tools. All I have to do is remember to check for any changes that the script attaches to my global file.
It seems to work pretty transparently for me. Hope this helps!
September 9: Updated to detect when new entries added to the configuration file are duplicated and ignored. This is useful for tools like SourceTree that will write new updates if they cannot find existing ones and do not contain include.
function git-config-update { $localPath = "$env:USERPROFILE\.gitconfig".replace('\', "\\") $globalPath = "C:\src\github\Global\Git\gitconfig".replace('\', "\\") $redirectAutoText = "# Generated file. Do not edit!`n[include]`n path = $globalPath`n`n" $localText = get-content $localPath $diffs = (compare-object -ref $redirectAutoText.split("`n") -diff ($localText) | measure-object).count if ($diffs -eq 0) { write-output ".gitconfig unchanged." return } $skipLines = 0 $diffs = (compare-object -ref ($redirectAutoText.split("`n") | select -f 3) -diff ($localText | select -f 3) | measure-object).count if ($diffs -eq 0) { $skipLines = 4 write-warning "New settings appended to $localPath...`n " } else { write-warning "New settings found in $localPath...`n " } $localLines = (get-content $localPath | select -Skip $skipLines) -join "`n" $newSettings = $localLines.Split(@("["), [StringSplitOptions]::RemoveEmptyEntries) | where { ![String]::IsNullOrWhiteSpace($_) } | %{ "[$_".TrimEnd() } $globalLines = (get-content $globalPath) -join "`n" $globalSettings = $globalLines.Split(@("["), [StringSplitOptions]::RemoveEmptyEntries)| where { ![String]::IsNullOrWhiteSpace($_) } | %{ "[$_".TrimEnd() } $appendSettings = ($newSettings | %{ $_.Trim() } | where { !($globalSettings -contains $_.Trim()) }) if ([string]::IsNullOrWhitespace($appendSettings)) { write-output "No new settings found." } else { echo $appendSettings add-content $globalPath ("`n# Additional settings added from $env:COMPUTERNAME on " + (Get-Date -displayhint date) + "`n" + $appendSettings) } set-content $localPath $redirectAutoText -force }
Ade Miller Aug 27 '13 at 15:22 2013-08-27 15:22
source share