Maintaining a Project with Git

Updated 15 June 2017

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.

Introduction

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:

  1. Checkout dev
  2. merge master into dev
  3. develop your code, making as many commits as you neet in dev.
  4. checkout master
  5. merge dev into master

If you follow steps 1-5 as a cycle, you shouldn't ever have to deal with merge conflicts. 

basic-git-branching-model

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.

Conclusion

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.

References

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.