Get Git — The Basics

Jennifer Olibie
5 min readMay 7, 2018

--

I know you must have asked couple of questions on what git is and what it does, and how it works. If I’m to guess, I’d say you must have come across the word Version Control a lot during your search.

What does this version control mean?

Let’s say you have a couple of people working on the same project, a text file for instance, each contributing, modifying, deleting and saving their parts simultaenously on that same text file. Now, it would be hard to know who changed what, when and why they changed something without asking everyone around. Here comes in version control.

Version control enables one to change, edit, delete, or work on a file by yourself or with a couple of people simultaneously while at the same time, taking note of what, when and why something was changed, that is, tracking each change. Not just that, you have the ability to revert changes, prevent someone from changing something or even recall a deleted part of the file. Isn’t that great?

There are many companies that host ‘git-ted’ applications but I’ll be using GitHub for my illustrations.

Simply put, GitHub is an application for hosting git applications in same way as Ms Word can be used to store word documents.

What Github is, is an online platform where such actions as version control explained above and collaborations on a file or project can be carried out by people in different locations.

I’ll explain the git terms as I proceed.

Let’s use a case study.

You, not necessarily a software developer, maybe writer, got a gig to work on a project and the customer insists she wants to see the progress of the work on GitHub. But you have no idea how to use GitHub, here are basic pointers.

First download and install git to your local working system (laptop). It’s really simple, just google this up.

Then visit Github.com and create an account.

Next you need to create a git repository - A repository is simply a place where the history of your work is stored. Git stores the version control information here.

Let’s say the name of the project is genesys.

For now, your repo is empty because you have not done any work. So next, you need to have a version of this repo in your local working area (laptop in this case) in order to work easily either online or offline, you need to have a copy of the repo in your local working system (laptop).

So you open your git bash in the directory you want the repo to be stored by right-clicking and selecting ‘Git Bash Here’. Make sure you have installed git.

This opens up a terminal, from which you would be issuing your commands.

The first thing to do is to clone (download) the repo which you had created earlier. Copy the link to the repo.

And paste it in the terminal after the git clone command. Now, you have a copy of the repo in your laptop(local repo) and it should appear as a folder in the directory that you git bashed at and we have to the change directory in order to start working inside the repo we just cloned using the cd command.

All the work we do will be done in relation to the genesys folder.

Here, I have a file in the genesys folder and the customer wants to see the progress I’ve made so far and make changes. So I need these changes to reflect in the repo online. I run the commands as follows:

basic git commands
  • git add . -> This is to prepare ALL my files to be committed(saved), technically known as staging my files. It allows git to tracking the files and changes made to it. Note the . after the add, you can add a particular file by specifying the file path after add instead.
  • git commit -m “commit message” -> This is saving my file in my local repo. They serve as checkpoints for changes made to a file. -m indicates message while the message itself is inside quotes. The message must indicate clearly, what you saved/changed and why
  • git push origin master -> This is the final stage in which I send the committed files to the repo online. So the customer now has access to it and can modify it if they so wish. origin indicates the source of the repo while master indicates the branch we are on(we’ll talk about this in another article).

Assuming we add made other changes to the local repo folder-genesys, we can check the state of that repo using git status command.

Here, I added a new file without staging it for commit.

Here, I added a new file, staged it for commit but have not commited it.

There are so many other git commands like git log which lists all the commits made on a repo , git diff which you can use to check the difference between two commits, git pull which you can use to keep your repo up to date with changes in the online repo, etc. Try them out. Take courses on git. Pave your way to open source contribution.

Never stop learning.

--

--