How to Install Git on Windows Server 2012 R2

Git is the industry-standard distributed version control system, and having it installed on Windows Server 2012 R2 is essential for any development, deployment, or DevOps workflow. Whether you are cloning repositories for automated builds, committing configuration files to version control, or scripting deployments that pull from Git remotes, a properly configured Git installation on your server is foundational. This guide covers multiple installation methods, Git configuration for server use, credential management, SSH key setup, and integration with PowerShell workflows.

Prerequisites

  • Windows Server 2012 R2 with administrator access
  • PowerShell 4.0
  • Outbound internet access on TCP ports 443 (HTTPS) and 22 (SSH) to reach Git remotes
  • Optional: Chocolatey package manager for automated installation

Step 1: Download Git for Windows

Git for Windows (also known as msysGit or Git SCM) provides the Git binary, Bash shell, SSH client, and credential helpers in a single installer. Download the 64-bit installer from the official Git for Windows project:

$GitVersion = "2.45.2"
$InstallerUrl = "https://github.com/git-for-windows/git/releases/download/v${GitVersion}.windows.1/Git-${GitVersion}-64-bit.exe"
$InstallerPath = "C:TempGit-${GitVersion}-64-bit.exe"

New-Item -ItemType Directory -Path "C:Temp" -Force
Invoke-WebRequest -Uri $InstallerUrl -OutFile $InstallerPath

Alternatively, install via Chocolatey if it is already configured on your server:

choco install git -y --params '"/GitOnlyOnPath /NoShellIntegration /WindowsTerminal"'

Step 2: Install Git Silently

The Git for Windows installer supports an unattended mode with an INF configuration file. For a server installation, the most relevant settings are: add Git to the system PATH, use the Windows Certificate Store for HTTPS, and enable symbolic link support:

Start-Process -FilePath $InstallerPath -ArgumentList `
    "/VERYSILENT",
    "/NORESTART",
    "/NOCANCEL",
    "/SP-",
    "/CLOSEAPPLICATIONS",
    "/RESTARTAPPLICATIONS",
    '/COMPONENTS="icons,extregshellhere,assoc,assoc_sh"',
    '/o:PathOption=Cmd',
    '/o:CRLFOption=CRLFCommitAsIs',
    '/o:BashTerminalOption=ConHost',
    '/o:UseCredentialManager=Enabled' `
    -Wait -PassThru

The /o:PathOption=Cmd option adds Git and its Unix tools to the system PATH, making git.exe available from any PowerShell or CMD window. The /o:UseCredentialManager=Enabled option enables Windows Credential Manager for storing HTTPS credentials securely.

Step 3: Verify Installation

Open a new PowerShell window to pick up the updated PATH and verify Git is accessible:

git --version
git config --list --system

Find the Git binary location:

Get-Command git | Select-Object Source

Step 4: Configure Global Git Settings

Configure the user identity and core settings that apply to all repositories on this server. On a build server or deployment server, use the service account’s identity:

git config --global user.name "Build Server"
git config --global user.email "[email protected]"

# Use Windows line endings in working tree, LF in repository
git config --global core.autocrlf true

# Set default branch name
git config --global init.defaultBranch main

# Enable long path support (important on Windows for deep directory structures)
git config --global core.longpaths true

# Use Windows Certificate Store for SSL verification
git config --global http.sslBackend schannel

# Cache credentials for 1 hour (3600 seconds) if not using Windows Credential Manager
git config --global credential.helper "cache --timeout=3600"

Step 5: Enable Long Path Support in Windows

Git on Windows requires long path support to be enabled in both Windows and Git to handle repositories with deep directory structures (common in Node.js and .NET projects):

# Enable long paths in Windows (requires reboot)
Set-ItemProperty -Path "HKLM:SYSTEMCurrentControlSetControlFileSystem" -Name "LongPathsEnabled" -Value 1 -Type DWord

# Enable in Git
git config --system core.longpaths true

Step 6: Configure SSH Authentication

For automated deployments that pull from Git remotes without interactive credential prompts, SSH key authentication is preferred. Generate an SSH key pair for the build service account:

# Use the ssh-keygen bundled with Git for Windows
$SSHKeyDir = "$env:USERPROFILE.ssh"
New-Item -ItemType Directory -Path $SSHKeyDir -Force

$SshKeyGen = "C:Program FilesGitusrbinssh-keygen.exe"
& $SshKeyGen -t ed25519 -C "[email protected]" -f "$SSHKeyDirid_ed25519" -N '""'

Display the public key to add to GitHub, GitLab, or Gitea:

Get-Content "$env:USERPROFILE.sshid_ed25519.pub"

Add the public key to your Git host’s SSH keys section, then test the connection:

$SshExe = "C:Program FilesGitusrbinssh.exe"
& $SshExe -T [email protected]
# Expected: "Hi username! You've successfully authenticated..."

Create an SSH config file to map hostnames to keys, which is useful when connecting to multiple Git hosts:

$SSHConfig = @"
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519
    StrictHostKeyChecking accept-new

Host gitea.internal.domain.local
    HostName gitea.internal.domain.local
    User git
    IdentityFile ~/.ssh/id_ed25519_gitea
    Port 22
    StrictHostKeyChecking accept-new
"@

Set-Content -Path "$env:USERPROFILE.sshconfig" -Value $SSHConfig

Step 7: Configure Windows Credential Manager for HTTPS

For HTTPS authentication (GitHub tokens, GitLab tokens), use the Windows Credential Manager helper bundled with Git:

git config --global credential.helper wincred

Store credentials for a specific host programmatically (for scripted setup):

$credManagerPath = "C:Program FilesGitmingw64libexecgit-coregit-credential-wincred.exe"

# Store credentials
$credInput = "protocol=https`nhost=github.com`nusername=your-username`npassword=your-pat-token`n`n"
$credInput | & $credManagerPath store

Step 8: Test a Repository Clone

New-Item -ItemType Directory -Path "C:Repos" -Force
Set-Location "C:Repos"

# Test clone via HTTPS
git clone https://github.com/youorg/yourrepo.git

# Test clone via SSH
git clone [email protected]:youorg/yourrepo.git

Step 9: Configure Git for Build Pipeline Use

In build scripts, suppress interactive prompts and configure Git for non-interactive use:

$env:GIT_TERMINAL_PROMPT = "0"   # Disable interactive password prompts
$env:GIT_SSH = "C:Program FilesGitusrbinssh.exe"  # Use bundled SSH

# Clone with depth for faster CI builds
git clone --depth=1 --branch main [email protected]:youorg/yourrepo.git "C:BuildsSource"

# Fetch latest changes in an existing clone
Set-Location "C:BuildsSource"
git fetch origin
git reset --hard origin/main
git clean -fd

Step 10: Verify Git Configuration Summary

Write-Host "Git version: $(git --version)"
Write-Host "User name  : $(git config --global user.name)"
Write-Host "User email : $(git config --global user.email)"
Write-Host "Credential : $(git config --global credential.helper)"
Write-Host "Long paths : $(git config --global core.longpaths)"
Write-Host "SSH binary : $env:GIT_SSH"

Summary

Git for Windows is now installed and fully configured on your Windows Server 2012 R2 machine. The installation includes the Git binary on the system PATH, Windows line ending handling, long path support, SSH key authentication for passwordless remote operations, Windows Credential Manager integration for HTTPS token authentication, and a non-interactive configuration suitable for automated build and deployment pipelines. This Git installation serves as the foundation for every subsequent DevOps workflow on the server, from Jenkins pipelines and MSBuild automation to Ansible playbook repositories and Terraform configuration management.