Source control tools, like Git, and sharing sites, like GitHub, are essential resources for any developer. These resources are not only useful to software developers, but also to hardware developers, designers, writers, and just about anyone who works with text.
In this post I want to explain why source control and sharing sites are necessary part of your workflow, and how to get started with learning how to use Git and GitHub.
Table of contents
Modern electronics development is intertwined with software development. Even trivial gadgets contain a micro-controller that executes a program.
If you are reading this blog post, you are most likely using some kind of microcontroller, or perhaps a Raspberry Pi, as your development platform. It could be an Arduino board or an ESP32. Maybe a Micro:bit, or a Raspberry Pi Pico.
You can create interesting gadgets using a simple text editor and a compiler. In fact, that’s how we all start our journey into programmable electronics. For example, if you use the Arduino as your platform of choice, you quickly become familiar with the Arduino IDE. The Arduino IDE is a combination of a simple text editor with a C++ compiler optimized for ease of use.
Programming without change control
I remember back in the 80s and 90s, when I was still new to programming, that I would write my program and store it in a single file. In the beginning, I would just modify this single file and add new lines of code, fix bugs, break things, and experiment with new functions until I was satisfied with the outcome. When I broke something (and this happened often), I would try to fix the code by trying to undo the last few changes (that likely introduced the bug).
I realized that every time I would save the file that contained my program, all previous change history was lost. There was no way to go back to a previous version of the file, except by trying to remember what I did and try to undo those changes from memory. Needless to say, my memory is not optimized for keeping track of code changes.
So, I changed by process. Every time I started working on a new feature, I would copy my current code into a new file, and just append the version number to the file name. For example, “my_great_program_v1.c” became “my_great_program_v2.c”, and so on.
This allowed me to keep a basic history of my programs, as they evolved. It was a crud method, but it worked. Every major version file contained a program that worked. Files with a minor version number, like “v1.2” contained experimental features or unfinished code. If I broke something, I could go back to a major version file and try again.
A big problem with this method is that it was not easy to quickly compare two versions of a program. For example, what are the differences between v1.0 and v1.2? I would need to use an external file comparison tool to find out, a tedious process.
When I got my first “proper” job in the late 1990s as a software developer for a publishing company, I started using a tool specifically designed to solve this problem. It was called CSV, short for Concurrent Versions System.
Some people still use it.
Source control tools are useful because they provide an integrated way to manage code that works for both solo developers and for teams.
At the very least, a source control system keeps track of changes in a programming project. The project may involve multiple files. The source control system allows you to capture those changes, give you a complete history of those changes (that can be marked with tags, full descriptions, and time-date stamps), compare between versions, and check out your program at any point in its captured history.
If you are working in a team, a source control system can also prevent two people from working on the same file by restricting access.
As a developer and member of a programming team, using source control had a profound positive effect in the quality of my work. I was able to experiment on new features without compromising existing tested work. I was also able to quickly see the differences between different versions of my own work, but also find out exactly what changes a team member had made to a file and went. I was also able to merge my new code to the project so and allow my team members to see it and comment on it (we had a quality controller who enjoyed giving out refactoring orders).
Source control and programmable electronics
After my software development “phase” finished, and came back to electronics, I naturally brought with me some of the most useful habits I acquired over the years. One of them was to integrate version control into my microcontroller programming projects.
By that time, in the late 2000s and early 2010s, Git was the most commonly used source control tool. Git was developed for programming in the era of Web 2.0, when social networks and remote working was becoming part of normal life.
Even though I was no longer in a team of programmers, I found that the benefits of using source control, and Git in particular, enormous.
No matter which language I used, the process was identical between projects. Git allowed me to keep a full history of my projects, experiment with features without fear of messing things up (especially easy when using a new branch for each experimental feature), and share all of this work with my students.
Of course, I wasn’t the only one. Social programming has exploded over the last 20 years. The open-source community was always generous with sharing its work with everyone. But with Git, and online code sharing services like Github, sharing has reached new levels.
Social coding and GitHub
While Facebook and Twitter are filled with pet videos and photos, as well as people abusing each other clinging onto half-baked illogical arguments, social coding, and sharing sites such as Github, Bitbucket and Youtrack have transformed how we share and reuse code.
These sites are powered by modern source control systems and allow people to share their code with others. On a site like GitHub, you can search for Arduino code, see its full development history, download it, make changes (like add a new feature or fix a bug), upload these changes to the same repository, and make a pull request so that your work can be used by others.
These sites often offer more than straight source control. For example, you will often find bug trackers that allow you to report bugs so that the project developers and owners can fix them (see an example of how bug tracking works for KiCad, and here’s the bug tracker for the Arduino project).
Modern source control has very strong social functionalities integrated to its core. The effect of this is that the community naturally expects that any project worth sharing will be shared on a Git (or equivalent) site (like Github and BitBucket). If a project is not on one of those sites, it will be much harder to find (if at all), and certainly very difficult to manage.
I dare say that if a software project is not on a site like GitHub or BitBucket, it is probably dead already.
Git is not only for programs
I want to emphasize that Git is not only for programs (like Python, C, etc.).
Git (and other source control system) is able to track any project that contains text-based files.
I have done a lot of work with KiCad, and share many of my PCB projects on GitHub. Here’s an example of a small PCB I designed for one of my courses. All files and their history is on Github, available to anyone who wants it.
Modern source control tool allow you to record the full history of the entire hardware-software project. Libraries, configuration files, core firmware files, schematics, PCB layout; everything can be captured, with full commentary, tags, dates, main and experimental branches.
And if you work in a team, you will always know who to blame when something breaks 🙂
How to learn Git and GitHub
When students ask me how to get started with source control, I answer as I do with any other similar “How to learn anything” question.
I am in favor of optimizing learning for efficiency. For me, efficiency is time to learn + effectiveness. I want to learn something as quickly as possible and to be able to use what I learned in my projects quickly.
This is why when someone asks me about which micro-controller to learn first, I say “Arduino”. When they ask which programming language to learn first, I say “Python”.
(Yes, there are many factors to consider when answering such questions, but let’s keep things simple).
In my opinion, anyone wanting to learn how to use a source control system should like Git. There are others, of course (see SVN, CVS, Perforce, and Mercurial), but Git is, by far, the prevalent technology.
In other words, if you don’t have a reason to NOT use Git, you should use Git. Git has excellent documentation, and it is refined to ensure trouble-free operation. It is also used across a huge spectrum of applications, from small single-person projects, to large projects with millions of lines of code and hundreds or thousands of developers.
Git also has a huge array of learning resources.
From there, you can browse through literally thousands of online Git guides, tutorials, blog posts, and videos to learn from.
Now, let’s turn to GitHub. As with source control, there are numerous online code sharing/social sites to consider. GitHub is just one of them. Others include BitBucket, SourceForge, Gogs (self-hosted), and Gitbucket (self-hosted).
As with Git, I find that GitHub is an excellent choice, especially for beginners, because of its clear user interface, abundant documentation and pricing (there’s a very generous free tier).
These resources will keep you very busy, and will help you get started.
Git and GitHub for Beginners
At Tech Explorations, we wanted to offer an integrated learning solution so that you can learn Git and GitHub together.
This is the most efficient path to learning how to use both.
The course is created by Vlad Budnitski, an electrical engineer, software developer, and instructor who uses Git and GitHub in a variety of settings: from large corporations like Intel to small startups.
Vlad’s lively instructional style is sure to engage you much more than still text on the screen 🙂
Quick facts about this course:
- Git and GitHub video course.
- Master practical key concepts and workflow of Git and GitHub.
- 6.5 hours of video content.
- Certificate of completion.
- Full lifetime access.
- Dedicated community discussion space. (With Community or Mentor Tier purchase).