[CmdletBinding(SupportsShouldProcess)]param( [switch]$sudo ) $local:workTree = git worktree list --porcelain | Select-String worktree | ForEach-Object { $_ -split 'worktree ' } | Where-Object { $_ } $local:sudoCmd = [string]::Empty if( $sudo ) { $sudoCmd = "env sudo" } Push-Location $workTree $null = Invoke-Expression "& $sudoCmd git reset HEAD 2>&1" $null = Invoke-Expression "& $sudoCmd git rm --cached -r . 2>&1" $null = Invoke-Expression "& $sudoCmd git add . 2>&1" git status Pop-Location