So I've finally got around to taking a look at Source Control for Umbraco and figured out what I believe are two suitable solutions. It was a bit of a learning curve and needed a fair bit of thinking and testing.
I hit a few road blocks along the way but nothing major. I thought I would document these problems here to help someone out who might be trying to figure out how to do the same.
So I've written two articles which are closely related....
1. This been the first and details Umbraco Source Control when using Umbraco Cloud & GitHub
This is the ideal solution if you're making use of Umbraco Cloud. This is the recommended way since Umbraco Cloud has really simplified media and content deployment.
2. The second which can be found here and details Umbraco Source Control using only GitHub
This method is suitable for anyone (like myself) choosing to host your Umbraco website outside of Umbraco Cloud on third party hosting or your own server. This method is slightly more difficult but I've documented this well to make it nice and easy for you.
Regardless of the which method is best for you I still recommend running through this tutorial first. There is some valuable information in here that will help you in both methods. It takes a few seconds to set up Umbraco Cloud, its very easy to use, and its free for trial purposes. You can create an Umbraco Cloud account here https://umbraco.com/campaigns/try-umbraco-today/.
1. Signup and create a test site for Umbraco Cloud.
Tips: Once I was up and running with Umbraco Cloud I installed "The Starter Kit" so I had some real data to work with rather than a blank website.
2. Download and install Git locally.
3. Create a GitHub account if you haven't got one already.
4. Download and install GitKraken locally.
I'm going to make this article short since Andrew Barta already did an awesome job on a series of Umbraco TV videos which will better document the steps involved. this article will just summarise on these steps and point out the issues I had along the way.
You can find all the required steps in the videos here.
If you prefer not to watch video tutorials the same information can be found here within Umbraco's documentation.
Step 1 - Setting up your Visual Studio solution & linking it to your Umbraco Cloud repository.
Umbraco has a preferred way of setting up the Visual Studio solution which works best when using Umbraco cloud. This is not set in stone and I personally do it a different way for my projects. I generally don't use Umbraco Cloud so this is the reason why I do it different. For the case of this tutorial and if you're using Umbraco Cloud then I suggest you setup your solution this way.
Umbraco have basically made this a piece of cake by setting up a bat / executable to set everything up for you. This can be found here.
When I ran through the script not all the solution files had been created as per Andrew's example. What I found was just one folder had been created that was named with a Guid. Inside was the Umbraco website files. There was no solution file or anything like that. To fix this I deleted everything and ran the script again and it worked. I tested this a number of times and it seemed quote temperamental. Sometimes it worked and sometimes it didn't. Just try a couple of times and I think you will be good.
Step 2 - Linking custom code to your own GitHub repository.
So Umbraco wants you to separate the source control off into two repositories. The first as described above is stored within Umbraco Cloud which they also use Git for. The second is any custom code is separated off into your own Git repository. This includes things like custom models, controllers, and other custom business.
So I encountered a couple of issues here which took me a while to figure out.
1. I cant remember the exact error message for the first issue but when I ran through the Git commands from Andrew
git remote add origin https://github.com/DavidArmitage/GitDemo.git
git push -u origin master
It bombed out with some sort of error message. I googled and it seemed that it was due to the remote version been later than that local (somehow). Anyway I tried starting from scratch a number of times. I tried re-installing git etc and still the exact same issue every time. I did some more digging around and instead of following the two command lines above I followed the ones from this URL and it worked a treat every time.
2. I also experienced the same issue Andrew was having in his example.
Fatal: the remote origin already exists
In-fact if you are testing like me and decide to create a few repositories you will encounter this issue a lot. Andrew's fix will save your life. Simply run it and try again.
git remote rm origin
Step 3 - Testing & Committing
So that's it. You should be good to go!
Remember if you are looking to host your website outside of Umbraco Cloud and want to know how to get up and running with source control please refer to my followup article here.