Git in PowerShell on Windows: Installing Git, Generating an SSH Key, Adding It to your SSH-Agent, and Using GitHub
I’ve been a long-time fan of Linux and MacOS for development, but I recently set a challenge for myself to set up my development environment in Windows PowerShell. One part of that is working with Git and repositories in GitHub.
Step 1: Install and configure OpenSSH
- Click the Start menu and navigate to Settings -> Apps -> Apps & Features -> Optional Features (or just press the Windows key and search for “Optional Features”)
- In the “Optional Features” window, check to make sure OpenSSH Client is in the list. Otherwise click Add a feature and add it.
- Press the Windows key or open the Start menu and search for “Services”
- In the “Services” window, double-click on “OpenSSH Authentication Agent”
- Change “Startup type” to
- Click the Start button under “Service Status”
Step 2: Install Git
- Download Git for Windows and run the installer.
- At the “Adjusting your PATH environment” step, select the “Git from the command line and also from 3rd-party software” option.
- At the “Choosing the SSH executable” step, select “Use external OpenSSH”.
- Choose the rest of the options at your discretion.
- (Optional) Install Posh Git and other helpers.
- Right-click PowerShell and click “Run as Administrator”
Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force
- Close that window and open PowerShell normally.
Install-Module posh-git -Scope CurrentUser -Force
Add-PoshGitToProfile -AllHoststo load posh-git automatically whenever PowerShell starts.
Step 3: Generate the SSH Key and add it to GitHub
- Open PowerShell
ssh-keygen -t ed25519 -C "firstname.lastname@example.org"and follow the prompts.
ssh-add.exe ~\.ssh\id_ed25519to add the key to your ssh-agent.
Get-Content ~\.ssh\id_ed25519.pub | clip. This will copy the public key to your clipboard.
- Add a new SSH key in GitHub and paste the public key into the “Key” field