Skip to content

Clone-Shallow

Clones a shallow Git repo

param([string]$URL = "", [string]$branchName = "main")

try {
	if ($URL -eq "") { $URL = Read-Host "Enter the URL to the remote Git repository" }
	$stopWatch = [system.diagnostics.stopwatch]::startNew()

	& git clone $URL --depth 1 --single-branch --branch $branchName --filter=blob:none --recurse-submodules --shallow-submodules --jobs 4
	
	[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
	"? Cloned '$branchName' branch from $URL in $($elapsed)s."
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

Specifies the URL to the remote Git repository (queried if none given)

Specifies the branch name ('main' by default)

An interactive directory of PowerShell scripts.