Are you new to Coding? This series of articles is a beginners’ overview of version-control, Git and GitHub.
In part 1 of this series, we learn that GitHub is an online service for hosting your Git repositories.
In part 2 of this series, we learn some of the key concepts and terminology related to Git.
In part 3 of this series, we learn how to use GitHub to create a new empty repo.
In part 4 of this series, we install Git on our local machine and clone our new GitHub repo.
In part 5 of this series, we learn how to begin working with Git - how to commit files, how to push them to GitHub and more.
In part 6 of this series, we learn how to work with Git branches - how to create them, move between them and merge changes.
Part 1 - Introduction
As a complete beginner, your journey into coding has probably led you to ask questions such as “how do I start programming?” and “what language should I learn?”. Maybe you’ve already chosen a language and you’re now thinking that you should be focussed on just learning how to code.
However, I recommend that you divert some of your efforts into learning about something called version-control.
This is knowledge that will serve you extremely well, regardless of what programming language you use.
Knowing how to use version-control will provide you with a system for recovering from accidental mistakes and open up a world of open-source code available on the internet.
If you’re intending to make a career in programming, then you should be aware that all professional employers will be using a version-control system themselves. Adding version-control to your skillset will give you a great advantage when applying for developer jobs.
Learning how to use version-control can be quite confusing for beginners. I promise you that this is a subject that is completely worth your time learning… so if you get stuck, definitely persevere!
What is version-control?
tl;dr : A service for storing and retrieving snapshots of your code.
A version-control system gives you the ability to take “snapshots” of your work. These snapshots are taken periodically as part of your workflow, typically when you have completed a task, which may involve making changes to one or more files.
When you take a snapshot, you provide a brief description to accompany those changes. Later, you can easily review the history of your snapshots. With the right tools, you can literally highlight the changes between different versions of your files.
Typically, your version-control software will be hosted in the cloud, although some companies may have their own onsite server for this purpose. Regardless, it means that a copy of your work can be saved permanently and safely, so you can recall it later if you need it.
The service where your code gets saved to is called a repository. It is very common for people to abbreviate this to “repo” (“ree-poh”).
Do I really need to bother with version-control?
tl;dr : Yes you absolutely do!.
Rather than list all of the features of version-control and the reasons why you should use it, let’s look at some scenarios that you’ll likely encounter in the real world - along with what you could do if you chose not to use version-control:
“I just want to hack out some code (small experiments and exercises etc.), so I really don’t mind if I lose all of my work - so I don’t need to back it up.”
- If you’re genuinely not fussed if you lose your work, then that’s ok!
- If you’re genuinely not fussed if you lose your work, then that’s ok!
“I’m putting a tonne of effort into learning how to code, but I’m so busy doing that, I don’t have the time to learn about version-control.”
Are you really ok with the risk of losing hours/days/weeks worth of effort? Your code is a record of your learning! What happens in six months time when your recollection of something isn’t so clear - wouldn’t it be better to know you could always refer back to your older code?
If your computer is lost, stolen or damaged - that work is completely gone.
If you accidentally delete a file or folder, there is a risk of loss. Most computers protect you from accidental file-deletes, by having the concept of a recycle bin that you can recover files from - but this is a fairly dangerous way to protect against accidental file-deletes.
When editing a file, if you delete or significantly change parts of your code… and then press save… those changes are permanent - there is no undelete.
“Ok, ok, I get that I really should be making a regular backup of my work. Aren’t there more simple alternatives?”
You could make a copy of the folder containing your work periodically - perhaps every evening. However, having multiple copies of your code takes up a fair bit of space and trying to figure out when a change was made to a file will be hard.
A better solution would be to make a zip of the folder. At least that would take less disk space.
You need to address the issues of keeping physically separate copies (i.e. don’t have your backups on the same laptop you carry around with you). A possible solution might be to copy the zip file to some cloud storage (e.g. a GoogleDrive or OneDrive, etc). Not a terrible solution, but still a bit clunky.
Your computer has automatic backup software. This is potentially a useful thing to have for “disaster recovery”, but how quickly and easily could you go back to an earlier version of your work?
“I’ve got my code working, but I now want to try adding in some new experimental feature; I don’t want to risk breaking my main code, so I kinda want to put the experimental code somewhere separate”
- You could make a copy of all the files, and then work on that copy. Not very elegant, plus if you want to keep the experiment, which copy of your files becomes the “current version”? How do you keep track of that? What if you have lots of experimental versions all in parallel - how would you go about merging it all back together?
I want to collaborate with other people, I’ve got a friend who wants to work with me on my project”
- You need some sort of network share - perhaps a Google Drive. You need to give permissions and copy your work onto that drive so your friend has access. Who has the most recent version? What happens if you’re working on a file at the same time? Trying to manually manage file versions will become a logistical nightmare very rapidly.
What version-control software should I be using?
tl;dr : You should learn and use Git
The answer to this question is similar to the question “what programming language should I learn?”. Strictly speaking, there is no single answer and it depends on your needs and who you will be collaborating with.
At the time of writing, a version-control system called Git has emerged as the most popular currently in use.
I recommend people new to coding learn how to use Git because:
It is hugely popular and if your intent is to begin a new career as a coder, you’ll almost certainly encounter it in the workplace.
“GitHub” (I’ll explain what this is properly, in a moment) is the most ubiquitous place on the web to find and collaborate with open-source code.
Compared to other systems, there are a number of technical advantages that come with using Git, which is one of the main reasons why it is the most popular in use today.
For the benefit of wider awareness, here are a handful of other popular version-control systems (there are many more):
An overview of GitHub
tl;dr : You should use GitHub
“I’ve heard of “GitHub” - is this the same thing as “Git”?”
They are related, but they are not the same thing.
Git is an open-source version-control system.
GitHub is a Git repository hosting service (cloud hosting).
GitHub can be completely free for individuals, or paid-for for other types of use (e.g. large teams who want to keep their code private).
It is hugely popular for hosting open-source projects. Such projects do not need to be for small groups or individuals - larger corporations use GitHub (for example, Microsoft keeps the source code for .NET Core openly available on GitHub).
FYI - Microsoft bought Github in 2018, at which point it had over 28 million users.
“Is GitHub the only option for hosting my Git repositories ?”
No, there are a number of other hosted options for Git, such as:
Azure DevOps (formerly called “Visual Studio Team Services (VSTS)”, which in turn was formerly called “Visual Studio Online (VSO)”)
SourceForge (although huge numbers of users left SourceForge to go to GitHub (when it arrived on the scene a decade ago), so this wouldn’t be a popular choice to make in 2019)
From my own experience, I previously would have recommended using Azure DevOps, because it provides free private repositories for individuals and small teams (up to 5). I would also have recommended this service, because it provides much more than just version-control, for when you start to get more advanced in your learnings (such as project management,code-building and deployment services).
However, as of the beginning of 2019, GitHub has announced that you can now host your private repos for free, whereas, previously this private repos was a premium service.
In this article, we’ve focussed on GitHub as being just a Git repository service, but it is more than that. GitHub is a platform for sharing ideas and code. This need not just be for programmers, as non-technical people can raise bug reports or suggest ideas.
Next, in part 2 of this series, we’ll learn about some basic Git concepts.