Skip to content

Instantly share code, notes, and snippets.

@SimonWahlin
SimonWahlin / pre-commit
Created March 27, 2018 12:22
Pre-Commit hook for git that will fix my user.email setting for me
#!C:\Program\ Files\PowerShell\6.0.0\pwsh.exe -File
$Pattern = '^origin\s+https://(\S+)\s\(push\)'
$Origin = (& 'git' 'remote' '-v') -match $Pattern | Where-Object -FilterScript {$_ -is [string]}
$RemoteDomain = if($Origin -match $Pattern) {$Matches[1]}
$Email = & 'git' 'config' '--get' 'user.email' | Where-Object -FilterScript {$_ -is [string]}
$DesiredEmail = switch -Wildcard ($RemoteDomain) {
'simonwahlin.visualstudio.com*' {
'[email protected]'
break