Sunday, September 29, 2013

VBA software development workflow for beginners using Git

Following on from my previous blog, now that we have Dropbox to hold our files together sorted. The next step is to allow changes made to these files into Git to track my changes made over time during the software development cycle.

So what is Git? A software (cloud based) solution to hold a snapshot of your file changed made over time and also to allow other people to create a branch from your code changes if you choose to.

In context, a practical and well known version control software. Git is an active member of the Software Freedom Conservancy which is a non for profit organization that promotes open source projects under the Creative Common License. Here is their free ebook from Git as background reading.

Let's get started...

I'm highly recommending our newcomers to have a go using their interactive web lessons learning from scratch what and to know how their Git "shell commands" are.

Download from Github their Windows / Mac / Linux platform of software onto your desktop, following their directions from the article to help set up your identity for Git and name your initial repository then your all set to go.

I prefer to use Git Shell than the graphical interface as this allows my fingers type away on the keyboard to ask Git to act on files I'm ready to import into my Git repository.

So, once I click on Git Shell icon which opens up the black dialog box. As indicated from my previous blog page. I have set up a directory for groceries from Dropbox. This is shown as a mapped drive letter Y:\ as my suggestion to save time locating the directory where ever you set up on your PC.

Y:\>cd groceries

The next thing to do is to initialize the directory for Git.

Y:\groceries>git init

Git will create some hidden files along the lines of "Initialized empty Git repository in Y:/groceries/.git".

A good programming habit to develop here is to always check the current status of what Git has before continuing.

Y:\groceries>git status

This shows a message that master is the first branch of changes and no other commits available (if shared with other people as they will have their own branches to update with your master)

# On branch master
# Initial commit
nothing to commit (create/copy files and use "git add" to track)

I will have placed a copy (using explorer onto this location) of my Excel file "groceries.xlsm" which basically acts a template going forward. I need to add this onto a staging area so Git has something to work with before committing my changes onto Github web page. While typing in "git add groce" you can use the TAB key to speed up typing the command to save time as the Git shell will recognise you wanted to complete the rest quickly.

Y:\groceries>git add groceries.xlsm
Y:\groceries>git add

also need to ensure there is a file. Readme file allows people on your Github have an idea what the repository is all about which we can update all sorts of useful information as we go along. "md" is short for markdown which I provide a link here that expands this concept better than I could.

Now I am ready to commit into Git.

Y:\groceries>git commit -m "J&J Groceries and first template"

then several message will display the result of committing your changes with the master. All this is doing at the moment is sitting on the "development side" of the equation (on Dropbox). To put this on the "production side" (to the cloud like Git) so to speak, we need to push the changes over to Github. Using the Github identity you have made eariler, you will have a secure web page address (with https://) which you can push your changes onto your web page. I have already set mine, the interactive web page provides a good example for you to do one.

Y:\groceries>git push

however when you examine my own Github page. I have made some prior commits as a test to check things are looking good. Now to see what changes I have actually made, you can visit my Github website, click on groceries.xlsm and select view raw to download yourself a copy to see what's happening.

Please let me know if there are issues arises attempt to find and see the groceries.xlsm file.

Next, let see if I could get a software like Jerkins to pick up my any changes directly from Github to do its own testing separately of what I made in production works.

Til then,