Version Control for Scripters, Part 1

For my first post, I’d like to talk about version control, specifically for scripting.

Now, it’s common knowledge that a version control (VC) system is essential for any “real” programming project, but as a mostly solo scripter (I’m normally the only person who scripts in my team at work), I never thought about doing any VC for myself.  But over the years, as I’ve created batch files, shell scripts, vbscripts and now powershell scripts, I’ve been looking at the benefits of VC.  The most compelling reasons are below:

  1. The scripts are backed up on another server
  2. You can undo changes, look back at old versions, and compare differences between versions
  3. You have a record of what changed on each version, as well as when it changed

For the most part, I’ve always backed up my scripts, so that was less of a worry for me.  I’ve also been using dropbox to store my scripts, so rolling back to previous versions was also fairly easy.  However I’ve never been very good at documenting my changes, so this might force me to get better.  Additionally, I found that if I set up a new ProjectLocker account for each company I worked for, I could keep all my scripts online and private, while still giving my colleagues access.  Then when I leave, my colleagues can still have access to my scripts, as well as the history of changes made to them.

Below is how I set up version control for my scripts, specifically using ProjectLocker and Git with TortoiseGit.

  1. Download the TortoiseGit package relevant to your architecture (32 or 64 bit) and install it.  The installation is fairly straightforward, so clicking Next a few times should be all that is needed.  Make sure to leave the SSH client on TortoisePLink.
  2. Download Git for Windows and install.  Again, not much customisation is required during installation.  On the Adjusting your PATH environment page, I selected Run Git from the Windows Command prompt, however the default will be fine too.
  3. Sign up for a free account at ProjectLocker.  Since you can only create 1 project with the free account, I call my initial project AllScripts.  Make sure to choose Git as the Repository Type.
  4. After the account has been created, log into the portal, answer the survey questions and create your security question and answer.
  5. Run PuttyGen from under the TortoiseGit menu and generate a key.  I prefer to enter my email address as the comment.  Enter a password and save the private key to a secure location.
  6. Copy the public key from the PuttyGen window.
  7. Open the ProjectLocker portal home and select Manage Public Keys.  Create a New key.  Enter a name, your email as the username, and paste the SSH public key into the Key field.  Save to finish.
  8. Go to User Home and copy the Git Location.
  9. On your PC, create a folder that you will use as the base for your scripts.
  10. Open the folder, right-click on a blank area and choose Git Clone…
  11. Paste the Git Location into the URL field.
  12. Tick Load Putty Key and browse to where you saved the ppk file.
  13. Click OK and enter the password.
  14. Accept the Putty key warning.
  15. You should get a confirmation that you have cloned an empty repository.

That’s the setup complete.  Now all your scripts can be copied to the AllScripts folder, ready for synching with ProjectLocker.  In my next post, I’ll talk about the process of adding, uploading and working with the VC system for your scripts.