· git ssh windows

SSH With Git Bash and TortoiseGit for Windows

Git for Windows

If you’ve ever written code of any kind for professional and personal purposes, you’ve likely come across the concept of Source Control Management (SCM). When I first became a developer, I used Subversion as my SCM tool but have since switched to the more popular Git. I use git to commit the latest versions of code in both Linux and Windows environments, but I’m going to focus on Windows in this post as this is the operating system for my personal computer.

Git itself is strictly a command-line tool and in setting up my Windows machine, I wanted the ability to make passwordless commits via bash commands or through my favorite git GUI tool, TortoiseGit. Why passwordless? It’s gets quite annoying having to enter your Github credentials every single time you push repository changes. Through the use of SSH keys, there is a secure way of doing this that allows Git Bash (or Cygwin) and TortoiseGit to play nice together. I didn’t find any good current documentation for this and had to mess around a bit to get the setup I now use, hence the reason for this post.

Step 1

Download the latest version of Git for Windows and install it. I would recommend you use most of the default settings, including running Git from the Windows Command Prompt so you can use Cygwin as your command-line tool if you prefer it over Git Bash, which comes with this download.

Installing Git

Step 2

Download the latest version of TortoiseGit and install it. There are no special steps to follow here, just keep hitting ‘next’.

Step 3

Generate an SSH key for your Github account following these instructions. At the end, be sure to test your SSH connection:

$ ssh -T [email protected]
# Attempts to ssh to GitHub

If you did everything correctly here, two files should now exist in a .ssh folder of your home directory (for Windows this will be C:\Users\username\.ssh). By the default they will be named id_rsa (the private SSH key) and id_rsa.pub (the public SSH key). If you have Microsoft Publisher installed on your computer, it will think the public key is a publisher file (because of the .pub extension). Use ‘open with’ to view this key in a text editor tool like Notepad++.

Step 4

TortoiseGit uses a PuTTY private key file format, so you will need to generate a private key in this format using the private key you generated following the steps from Github. Search your programs and files for PuTTygen, which should have been installed with TortoiseGit. Open this program and go to Conversions > Import key.

Browse to the private key file you generated via ssh-keygen (see step 4) and import this into PuTTygen. Click the ‘Save private key’ button after you have imported your private SSH key to save it in PuTTY private key file format (.ppk). You will want to save it to the same location as your other keys (the .ssh folder of your home directory, C:\Users\username\.ssh).

PuTTY Key Generator

SSH Keys

Step 5

In your Github repository, select ‘Clone with SSH’ and copy the URL path to the clipboard (make sure it starts with [email protected]). Use TortoiseGit to to clone a copy of your Github repository to your local machine (right click in the directory, then select Git Clone…). Paste the copied URL path into TortoiseGit. Check ‘Load Putty Key’ and browse to the .ppk file you created in Step 5.

TortoiseGit Clone

Hit ‘OK’ and that’s it! You now have a SSH repository on your Windows machine that you can push passwordless changes with using either the TortoiseGit GUI or the command line with Git Bash (or Cygwin). I tend to use TortoiseGit for one-off commits and automated deployment scripts through the command line for repositories I am frequently making changes to. Regardless of approach, it is nice to have TortoiseGit installed on your Windows machine to easily visually identify any uncommitted changes for a repository.

TortoiseGit Repo

andgoss@MYCOMPUTER MINGW64 /C/Github_AG/mssql-library (master)
# Push source and build repos.
git push origin master

About Me

I'm a data engineering manager working to advance data-driven cultures by wrangling disparate data sources and empowering end users to uncover key insights that tell a bigger story. LEARN MORE >>

comments powered by Disqus