Upload to Azure Devops – This push was rejected because its size is greater than the 5120 MB limit for pushes in this repository.

During uploading fresh repository to GIT especially to Azure Devops – you can see:

This push was rejected because its size is greater than the 5120 MB limit for pushes in this repository.

The idea is to split across the commits. Here is a script that can do it automatically based on file size.

Invocation from directory of where you have repo: ..\push-one-dir.ps1 -RepoUrl “https://dev.azure.com/organisation/SVN/_git/gitrepo”

# Push repository in batches under 4500 MB
# Run from the repository directory, e.g.: cd C:\svn\MNG then ..\push-one-dir.ps1

param(
[Parameter(Mandatory=$true)]
[string]$RepoUrl
)

# Start logging
$timestamp = Get-Date -Format “yyyyMMdd_HHmmss”
$repoName = Split-Path -Leaf (Get-Location)
$logFile = “C:\svn\logs\push_${repoName}_${timestamp}.log”

# Create logs directory if not exists
if (-not (Test-Path “C:\svn\logs”)) {
New-Item -ItemType Directory -Path “C:\svn\logs” | Out-Null
}

Start-Transcript -Path $logFile

Write-Host “========================================” -ForegroundColor Cyan
Write-Host “Starting push for: $repoName” -ForegroundColor Cyan
Write-Host “Repository URL: $RepoUrl” -ForegroundColor Cyan
Write-Host “Log file: $logFile” -ForegroundColor Cyan
Write-Host “Started at: $(Get-Date)” -ForegroundColor Cyan
Write-Host “========================================” -ForegroundColor Cyan

$maxBatchSizeMB = 4500
$maxBatchSizeBytes = $maxBatchSizeMB * 1MB

# Remove existing .git if present
if (Test-Path .git) {
Write-Host “Removing existing .git folder…” -ForegroundColor Yellow
Remove-Item -Recurse -Force .git
}

# Initialize fresh repo
git init

# Add remote
git remote add origin $RepoUrl

# First commit – just .gitignore
git add .gitignore
git commit -m “Initial commit – gitignore”
git push -u origin master –force

# Get all files (excluding .git and files matching .gitignore)
# Use -z for null-terminated output to handle special characters
$allFilesRaw = git ls-files –others –exclude-standard -z
$allFiles = $allFilesRaw -split “`0” | Where-Object { $_ -ne “” }

$currentBatchSize = 0
$currentBatchFiles = @()
$batchNumber = 1
$skippedFiles = @()

foreach ($file in $allFiles) {
# Clean up the file path – remove quotes if present
$cleanFile = $file.Trim(‘”‘)

if (-not (Test-Path -LiteralPath $cleanFile)) { continue }

$fileSize = (Get-Item -LiteralPath $cleanFile).Length

# If single file exceeds limit, skip it and warn
if ($fileSize -gt $maxBatchSizeBytes) {
Write-Host “WARNING: Skipping ‘$cleanFile’ – file too large ($([math]::Round($fileSize/1MB, 2)) MB)” -ForegroundColor Yellow
$skippedFiles += [PSCustomObject]@{
File = $cleanFile
SizeMB = [math]::Round($fileSize/1MB, 2)
}
continue
}

# If adding this file would exceed limit, push current batch first
if (($currentBatchSize + $fileSize) -gt $maxBatchSizeBytes -and $currentBatchFiles.Count -gt 0) {
Write-Host “Pushing batch $batchNumber ($([math]::Round($currentBatchSize/1MB, 2)) MB, $($currentBatchFiles.Count) files)…” -ForegroundColor Green

foreach ($batchFile in $currentBatchFiles) {
git add — $batchFile
}
git commit -m “Batch $batchNumber”
git push origin master

Write-Host “Batch $batchNumber completed at $(Get-Date)” -ForegroundColor Cyan

# Reset for next batch
$currentBatchSize = 0
$currentBatchFiles = @()
$batchNumber++
}

# Add file to current batch (keep original format for git add)
$currentBatchFiles += $file
$currentBatchSize += $fileSize
}

# Push remaining files
if ($currentBatchFiles.Count -gt 0) {
Write-Host “Pushing final batch $batchNumber ($([math]::Round($currentBatchSize/1MB, 2)) MB, $($currentBatchFiles.Count) files)…” -ForegroundColor Green

foreach ($batchFile in $currentBatchFiles) {
git add — $batchFile
}
git commit -m “Batch $batchNumber”
git push origin master

Write-Host “Batch $batchNumber completed at $(Get-Date)” -ForegroundColor Cyan
}

# Summary
Write-Host “========================================” -ForegroundColor Cyan
Write-Host “SUMMARY” -ForegroundColor Cyan
Write-Host “========================================” -ForegroundColor Cyan
Write-Host “Total batches pushed: $batchNumber” -ForegroundColor Green
Write-Host “Completed at: $(Get-Date)” -ForegroundColor Green

if ($skippedFiles.Count -gt 0) {
Write-Host “Skipped files (too large):” -ForegroundColor Yellow
$skippedFiles | Format-Table -AutoSize
}

Write-Host “Log saved to: $logFile” -ForegroundColor Cyan

Stop-Transcript