Yesterday was the first day of Commitmas, a community event thought up by Matt Brender to help us all get used to sharing code and working with GitHub. The challenges vary based on your level of comfort - I am starting in the beginner track and hoping to work my comfort level up to being a “beginner intermediate” by the end. Now I am no developer but I see the train coming, and for all the vCommunity out there I hope you see it coming at well. The future is code and scripts; Commitmas is a great way to prepare.
Last month I published a few posts on Ansible, as part of that I created a repository on GitHub to put my playbooks in. To get back into the swing of GitHub I decided to install Git on Windows, clone my Ansible repository and create a simple README file.
What little knowledge and hands on with GitHub I have has all been from a Linux based system. On Windows you lack some of the common tools you have with Linux such as the ability to create SSH keys or an SSH client. The Git install for Windows provides these for you. Installing Git for Windows is easy, thanks for course to Chocolatey.org; if you have not used Chocolatey before installing it is also quite simple. Open a cmd prompt as admimistrator and run
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
Now packages are as easy to install as running
choco install git
Once installed, we need to verify a few system settings:
- Go to Advanced system settings (Start >> Control Panel >> System >> Advanced system settings)
- Click on Environment Variables
- In the System variables section locate 'Path' and verify C:\Program Files (x86)\Git\cmd; is there
- Add C:\Program Files (x86)\Git\bin; directly after C:\Program Files (x86)\Git\cmd; with no spaces after the ; (make sure you also end with a ;)
- For SSH commands to work later, you need to add a variable. In the User variables for user section, click the New... button
- Create a variable named HOME with a value of %USERPROFILE%
- Click OK three times and reboot the computer. After the reboot you
After the reboot you should be able to open a cmd prompt and run ssh and not get a “ssh is not a recognized command” message
We are now ready to setup GitHub on Windows. If you haven’t done so already, create a user account on GitHub. There are a few commands we need to run to get everything ready.
- git config --global user.name username [where username is your actual username, for example jfrappier]
- git config --global user.email email@example.com [where firstname.lastname@example.org is your actual email that you signed up for GitHub with]
- ssh-keygen -t rsa -C email@example.com
- Select the location to save the key, I accepted the default
- Enter a passprhase
CD to %userprofile%.ssh; you should see two files - id_rsa and id_rsa.pub.
- Open id_rsa.pub in note pad and copy the contents
- Log into GitHub and click on Settings (the gear icon in the upper right corner) >> ssh keys
- Click Add SSH key
- Provide a name, paste the contents from id_rsa.pub into the key textbox, and click Add key
Now switch back to your cmd prompt window
- Type ssh -T firstname.lastname@example.org
- Type yes to accept the certificate
- Type the passphrase you set for your key previously
You are now authenticated with GitHub, you can now enjoy the 12 days of Commitmas!