Skip to content

Instantly share code, notes, and snippets.

@rapgru
Created April 26, 2020 14:57
Show Gist options
  • Save rapgru/561df5b95fb0a78f5934efefb19ea236 to your computer and use it in GitHub Desktop.
Save rapgru/561df5b95fb0a78f5934efefb19ea236 to your computer and use it in GitHub Desktop.
Install Git for Windows (https://github.com/git-for-windows/git) without bash
if(!(Get-Command git -ErrorAction SilentlyContinue)) {
$gitDir = "$env:LOCALAPPDATA\CustomGit"
if(Test-Path $gitDir) { Remove-Item -Path $gitDir -Recurse -Force }
New-Item -Path $gitDir -ItemType Directory
$gitLatestReleaseApi = (Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/git-for-windows/git/releases/latest).Content | ConvertFrom-Json
$mingitObject = $gitLatestReleaseApi.assets `
| Where-Object {$_.name -match "MinGit-[\d.]*?-64-bit.zip"} `
| Select-Object browser_download_url
Write-Host "Matching asset count: $((Measure-Object -InputObject $mingitObject).Count)"
if ((Measure-Object -InputObject $mingitObject).Count -eq 1) {
$mingitObject `
| ForEach-Object { Invoke-WebRequest -Uri $_.browser_download_url -UseBasicParsing -OutFile "$gitDir\mingit.zip" }
Write-Host "Installing latest release fetched from github api!"
} else {
Write-Host "There were more than one mingit assets found in the latest release!"
Write-Host "Installing release 2.26.2 instead!"
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/latest/download/MinGit-2.26.2-64-bit.zip" -UseBasicParsing -OutFile "$gitDir\mingit.zip"
}
Expand-Archive -Path "$gitDir\mingit.zip" -DestinationPath "$gitDir"
#Copy-Item -Path "$gitDir\mingit\cmd\git.exe" -Destination "$gitDir\git.exe" -Recurse
Remove-Item -Path "$gitDir\mingit.zip" -Recurse -Force
if(([Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)) -notlike "*$gitDir*") {
Write-Host "Updating PATH"
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User) + ";$gitDir\cmd", [System.EnvironmentVariableTarget]::User)
}
}
@rapgru
Copy link
Author

rapgru commented Dec 11, 2020

@electr0sheep Yes, I've already planned on doing that, but haven't found time for it yet! I'll post a link here when it's available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment