Let's have a very quick look at Git and Github - Git is an enormous topic, so this won't be an exhaustive tutorial but by the end of it we'll have a working knowledge of basic git workflow.
I'll be showing this tutorial on a Raspberry Pi, but you can follow along on any machine that has the Git framework installed.
Developing a code-based project on a Raspberry Pi can suck. Not by any fault of the Pi, but because we often expose them to environments, shocks, or temperatures that a computer doesn't typically see. It'd be a shame to lose a project that you've sunk many hours into just because your SD card corrupted or your Pi-controlled rocket crashed (ok maybe you have bigger problems there).
Enter Git and Github. These are professional-grade tools that you can use for free that help you version-control and back up your coding projects. If you blow your Pi up, no worries. You can just clone your project from your online repository and redeploy in minutes.
Git: The gist
Git is a version control system for keeping track of changes to files. If you're working on a project and you want to experiment with adding a new feature or try different debugging approaches, Git allows you to track changes you've made. When talking about Git, we often mention the phrase repository (or "repo") which refers to the project contents: files and information about all the changes that have been made to them.
When we reach a milestone (worked out a new feature, or just finished working for the day) we perform what is called a commit. This saves the state of the repository and we can reset back to a commit at any time.
Github is simply a web-based Git management platform that adds a few features like bug tracking, feature requests and commenting, to name a few. These features make Github a great platform to collaborate with makers all over the globe.
In this tutorial I'll be working with the Github web-interface and the command-line tools on a Raspberry Pi.
Within your command-line interface (terminal), type git. If you get the git help text then you already have git on your computer. If you need to install git, the command in Raspbian would be sudo apt-get install git-core.
From here, these written notes are only intended as reference material for this tutorial's video.
A simple branching model
For personal projects, I find the following branching model works well. If you find your projects growing in complexity, check out the links in the References section.
As a step-by-step procedure:
- Checkout dev
- merge master into dev
- develop your code, making as many commits as you neet in dev.
- checkout master
- merge dev into master
If you follow steps 1-5 as a cycle, you shouldn't ever have to deal with merge conflicts.
The master branch is kept as "release" versions - that is, versions that I'm happy are in a presentable state for anybody who would wish to download it. Changes are developed in the dev branch, and merged (or pulled) into the master branch when they are complete. The master branch is the default branch that visitors see when they browse to the github repository, so it makes sense to keep it as stable as possible. This model works for simple projects where you're working on only one thing at a time, seeing changes through until their completion before moving forward to the next task.
Git is intimidating - I get that. Hopefully now things are a little clearer on how to get started. If you choose to stick with it, the benefits of git and github are their powers to back up and manage changes to your projects, and to provide you a free platform to share and collaborate.
There's plenty of room to grow from here, too. Dan Shiffman's Youtube series, Git and Github for Poets explores these topics more in-depth, and covers using Github to host a free website for your project.
- Git and Github for Poets - Dan explores git more in depth, getting into collaboration tools and hosting a project-specific website
- The beginner's guite to contributing to a github project - A great little model if you want to help improve somebody elses project.
- A successful Git branching model - A robust model for really large projects with several collaborators. Specific rules about what branches may be used for and which branches can merge.