Why use git in programming is a common question among beginners. Some think it is unnecessary until they face the problems of not using it.
In this post, I will show you the main problems of not using it. So, you can decide if you should use it or not on your own.
Table of Contents
- The problem when we do not use git in programming
- What is git?
- How to use git in programming?
- Github (and git) as a tool to showcase your programming portfolio
- Git installation guides
- Next steps
The problem when we do not use git in programming
They say a picture is worth a thousand words. Let’s see the ones below and you can tell yourself if you feel identified with them.
You can also change part of the name of the folders as follow:
- Change thesis by project
- Thesis by assignment
Does it look familiar?
If your answer is yes, there is a simple solution for it: git.
Let’s check another scenario.
You are coding/programming to solve a certain problem. Let’s say you solved 60% of the problem.
Now you start adding new functionality or making one that is already implemented better (optimizing the code, using a coding style, any of the usual things we do to make our code look better to us).
You finish the coding and left it like that. You close the IDE or whatever you use to do the coding.
When you start working again, the code that use to work now does not work anymore. “Control+Z” also does not work because you closed the IDE or it crashed or the OS was restarted for an update. Many things can happen that can disable the “Undo” option.
Now, you have to spend some time (maybe hours), to get your code running again like it was running the previous day (or the previous 5 min). In other words, you have to repeat the same thing you already did, wasting your time.
If this didn’t happen to you, I can assure you, there is a high probability that will happen if you are a programmer, and you don’t use any version control system.
What is git?
According to the official git website: “Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency”.
The keywords to pay attention to are “version control system”.
There is no need for a definition for the previous keywords. Intuitively, we can understand that it is a system that controls versions.
So, every time we have a stable version (a version that works), we register it (“controlled”) on the system.
Let’s say like in the last example, once the program works, you “register” (you will see later the right term to use) that version on the control system.
Once several versions are registered, any time you can go back and use any of the versions that were previously registered.
As you can see, when you use this type of system, there is no way that you will have to spend time trying to get your code as it was before. A simple instruction to the control system can revert the code to a previous version (the version that works).
As a result, when you make mistakes trying to change the code (to make it better) you can correct them with one command, quick and clean.
Another part of the definition worth looking at is the keyword “distributed”.
Usually, the software is created by a team, not by only one person. So, the team need a system where they can share their artefacts (code, diagrams, etc.). This can also be achieved using git.
How to use git in programming?
There are many tutorials and good practices when using git.
Here, I’ll just refer to the rule of thumb when you use git to record versions of your code.
Beginners usually wait until they finish a big part of the software to record the code using git. From now on, we will refer to record as commit, as it is the command used on git. In this way, you can start already familiarizing yourself with the world of version control systems.
When you add version control to your code, you will refer to the place where the code is stored as the repository.
When you have a stable version of a code, you do a commit your code to the repository.
A great question is: how do I know when I have a stable version of my code? Or how big should be the next version of my code before I do a commit to the repository?
The answer to these questions is relative. But, as a rule, you should make your versions as smaller as possible. The reason is that the smaller the version, the easier to go back to a previous stable version and the easier for the team to work with your code.
Another rule is, before you do a commit, make sure your code is tested and it does not have errors (at least common errors that you should identify before releasing the code to the team). Probably the best way to test your code before doing a commit is by creating a unit test for the new code you wrote. You can learn about unit tests in this post. Although the example is in Java, similar reasoning is followed in several programming languages.
Github (and git) as a tool to showcase your programming portfolio
GitHub “is a provider of Internet hosting for software development and version control using Git.”
You can create projects on GitHub, using git to control the versions of your code. These projects can be private or public. You can even “copy” a project that someone else created also on GitHub and contribute to the project by using git and the tools provided on GitHub.
Several employers ask for the link to your GitHub profile nowadays. So, it is a good idea to create your projects there, and use them to showcase your programming portfolio.
Another great use of GitHub is to participate as a contributor in open-source projects. You can search on GitHub for projects that you are interested in and follow the contributions guidelines.
Git installation guides
There are a plethora of guides on the internet to install git and get started with it.
I always prefer to go to the main source and try to avoid repetition. That is the reason why I won’t write here how to install git, but rather give you the link to the official website that shows how to install it.
You can find the guide at this link. You will find in the previous link installation instructions for Mac, Linux and Windows.
To use git is also important few configuration steps that you can find in this link.
Once you finish with the configuration, it is the moment to start using the first commands. You can create a new project and add source/version control using git. You can download public projects from GitHub, etc.
A good way to start is to follow the tutorial provided on the official git website.
According to the description above, I recommend you do the following:
– Install git on your computer.
– Create a GitHub account using their official website.
– Create a new project on GitHub using your new account.
– Download the repository and start coding and doing commits.
If you don’t have a clear idea of what project to start, you can use any of the three projects below:
Don’t forget to extend the implementations you choose, so they have your personal signature.