Git for Windows - OSDeploy/OSD.Workspace GitHub Wiki

Quick Setup

# Install Git for Windows
winget install --id Git.Git -e -h

# Set user identity
git config --global user.email "[email protected]"
git config --global user.name "Your Name"

Documentation

Git for Windows

Download

Latest

Winget

Show all available versions

winget show --id Git.Git --versions

Show install version

winget show --id Git.Git

Install latest version

winget install --id Git.Git -e -h
# --accept-source-agreements
# --accept-package-agreements

PowerShell

Test if Git is installed and set user identity

$git = Get-Command git -ErrorAction SilentlyContinue
if ($git) {
    $gitVersion = git --version
    Write-Host "Git is already installed: $gitVersion" -ForegroundColor Green
}
else {
    Write-Host "Git is not installed." -ForegroundColor Yellow
}

Set user identity

# Check if user.email is set
$currentEmail = git config --global user.email
if ([string]::IsNullOrWhiteSpace($currentEmail)) {
    $userEmail = Read-Host "Enter your Git email address"
    git config --global user.email "$userEmail"
    Write-Host "Set git user.email to $userEmail" -ForegroundColor Green
} else {
    Write-Host "Current git user.email: $currentEmail" -ForegroundColor Yellow
    $changeEmail = Read-Host "Do you want to change it? (y/n)"
    if ($changeEmail -eq 'y') {
        $userEmail = Read-Host "Enter your new Git email address"
        git config --global user.email "$userEmail"
        Write-Host "Updated git user.email to $userEmail" -ForegroundColor Green
    }
}

# Check if user.name is set
$currentName = git config --global user.name
if ([string]::IsNullOrWhiteSpace($currentName)) {
    $userName = Read-Host "Enter your Git user name"
    git config --global user.name "$userName"
    Write-Host "Set git user.name to $userName" -ForegroundColor Green
} else {
    Write-Host "Current git user.name: $currentName" -ForegroundColor Yellow
    $changeName = Read-Host "Do you want to change it? (y/n)"
    if ($changeName -eq 'y') {
        $userName = Read-Host "Enter your new Git user name"
        git config --global user.name "$userName"
        Write-Host "Updated git user.name to $userName" -ForegroundColor Green
    }
}

# Show final identity
$finalEmail = git config --global user.email
$finalName = git config --global user.name
Write-Host "\nYour global Git identity is now:" -ForegroundColor Cyan
Write-Host "  Name : $finalName" -ForegroundColor White
Write-Host "  Email: $finalEmail" -ForegroundColor White