$ErrorActionPreference = 'Stop' $files = git ls-files foreach ($f in $files) { if ($f -notlike 'backend/*' -and $f -ne 'backend') { git rm -q --ignore-unmatch -- "$f" } } Write-Output "-- staged removals --" git status --porcelain=2 --branch $staged = git diff --staged --name-only if (-not $staged) { git commit --allow-empty -m 'Deploy: keep only backend (empty commit if no removals)' } else { git commit -m 'Deploy: keep only backend' } Write-Output "-- commit done --"