Last active
October 15, 2020 15:51
-
-
Save alanjaouen/cf4f52566f3c88b60960c9227bc200d7 to your computer and use it in GitHub Desktop.
Install git on windows without git bash and other git-for-windows shitty stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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!" | |
} | |
Expand-Archive -Path "$gitDir\mingit.zip" -DestinationPath "$gitDir" | |
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) | |
} | |
git config --global add.interactive.useBuiltin true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment