I Don’t Git It (Version Control)

iDev
5 min readSep 9, 2020

I was today years old when I learned and understood what Git was. Hidden in the MacOS(and Linux), there is a great functionality that makes any developers life so much easier. It’s no mystery to the programming world and perhaps the millions of developers using it as standard operating procedure. But after learning it today, not one of my projects will be done without using Git.

Let’s paint the picture shall we?

You are working hard on personal project for weeks, then one day you make a mistake or get rid of the wrong file and the project is broken. How do you restore the project to where it was before you made the mistake? Let’s say you want to add some new functionality to the project, how do you test the new code on your project without messing with that main(master) file? What if you are on a small team and you are all working on the same project changing different lines of code, how do you prevent bugs from two people changing the same line of code? These and more are the things using Git or version control can solve.

Version control is a software tool to help control the adaptations of a source code. You start with a source, then you can adapt it by making copies of it for others to work with. You can also refer to another point in time of the project, which may assist in finding certain bugs that weren’t present before. It allows you to get an idea of when the bug became present in the project.

Command + Z was an often used method of mine to undo everything until I got far enough to start over. Which is not a great way and can often introduce unintended removal of things that I didn’t want to. It’s fine to undo one or two things, but not practical in going back multiple steps. I didn’t know about Git or version control so I often had to restart a whole project over because I was so lost of where I was and what was wrong with the project. This caused discouragement and frustration which was not helping my iOS Development goals. But it also helped me realize what a valuable tool Git is.

Git is the code to type in the command line or terminal of your computer to basically do all things Git related. There are a couple of commands I would like to go over just to get a general idea of how to use version control.

The Process

We first need to make a file that is a repository, this is where everything is going to take place. This can either be created on your computer for personal projects or on an online hub for teams and shareability. I’m getting familiar with the online hub of GitHub. This is by far the most popular and broadly used in businesses according to recent surveys. But to make it simple we will just talk about making one on the local computer.

First, we create a file on let’s say the desktop. Then we open the terminal, navigate to the file and then use the commands “git init.” This initializes the file as a repository.

To add a file to the repository you need to use “git add.”

Once you have main or what’s called a “master” file, this will not be touched until you are sure you want to change the master file. All of your changes will be done to clones of this master file which is known as a “branch.” Just like a tree, a branch comes for the trunk of the tree. The trunk being the master file and the branch is the copy that we can trim or add to. To make a branch its “git branch.”

Once you have made changes to the branch, you can “commit” the changes and this makes a record of what was done so you can reference to this later if you need to go back to a previous change or commit. To commit, you guessed it, “git commit.”

There is a lot more functionality but these are the basics. To come full circle, say now you made all your changes and you have tested it and found no bugs and you are now ready to combine the changes done on the branch to the master file, we now need to merge the branch to the master.

That’s it, a very simplified explanation of version control. There are also GUI’s that make this process easier like the GitHub Desktop app to avoid typing the code. Git was developed in 2005, I couldn’t imagine working on projects, especially in teams, without it.

Rick Martinez

--

--