$ErrorActionPreference = 'SilentlyContinue' $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $root = (Get-Item (Join-Path $scriptDir '..\..')).FullName Set-Location $root $mainBranch = 'master' git show-ref --verify --quiet refs/heads/master 2>$null | Out-Null if ($LASTEXITCODE -ne 0) { git show-ref --verify --quiet refs/heads/main 2>$null | Out-Null if ($LASTEXITCODE -eq 0) { $mainBranch = 'main' } else { $mainBranch = (git rev-parse --abbrev-ref HEAD 2>$null).Trim() } } Write-Host '' Write-Host 'Files to be pushed:' Write-Host '========================================' $diff = git diff --name-status "origin/$mainBranch..HEAD" 2>$null if ($LASTEXITCODE -eq 0 -and $diff) { Write-Host $diff } else { $log = git log --name-status --oneline HEAD 2>$null $lines = $log -split "`n" | Where-Object { $_.Trim() -and $_ -notmatch '^[a-f0-9]' } if ($lines) { Write-Host ($lines -join "`n") } } Write-Host '========================================' Write-Host '' Write-Host "Pushing to origin/$mainBranch..." Write-Host '========================================' git push origin $mainBranch if ($LASTEXITCODE -eq 0) { Write-Host '' Write-Host '========================================' Write-Host ' success (Push successful)' Write-Host '========================================' exit 0 } else { Write-Host '' Write-Host '========================================' Write-Host ' failed (Push failed)' Write-Host ' Check error messages above.' Write-Host '========================================' exit 1 }