Introduction to Git

What VCS is, what Git is And how it works. What is branches, and how it works. Introduction to git

Introduction to Git

Intro

This is a post about what is git and why we should use git. We don’t talk about commands (maybe a little). We only understand the meaning of git.

What is git?

As an article, we say that git is a version control system. But as a fun article, we say git is a remote USB flash that you don’t need to carry.

When the first developers started to work on the same project as a team, they always had problems. Problems like sharing project files, working on one common file, history of changes, etc.

First VCS(Version Control System) was developed by Marc J. Rochkind at Bell Labs in the 1970s called "Source Code Control System" (SCCS).

When it was developed, all the developers refused to use it and they said “We always work solo. An eagle has always been solo!” (Just kidding. I was not there to know how they behaved. And I am not interested to know).

Just don’t act like a developer that refused to use VCS (Not specially git, All VCSs).

Why Git?

Why should we use git? Or the other version control systems? The answer is simple, because teamwork needs it. You can't work with a team that doesn't use Git.

Git helps you to share your codes, at the same time  works on a project, and collaborate with the other developers. Collaborate with your team, even in different locations.

Imagine if there was no git or other VCS, you had to share your files with email or other messengers. And you didn't know which file was changed by which developer.

VCSs developed to resolve your file change histories, teamwork problems, sharing files problem and versioning problem.

How does it work?

Trust me nobody knows how git works, even Linus Torvalds & Junio C Hamano. I'll just tell you what I found out.

Imagine you have a camera and you want to record all of your activity. You tell the camera to record your activity by pressing the record button.

Now if you want to record your all code change histories you should tell the git to record your changes. I mean, you press record ( git init ) and it starts to record your activities (changes).

The camera is recording your activities, but if you don't press the stop button, the activities will never be saved for you.

Pressing the stop button is like you add your changes to stage (Will tell you what stage is) and then commit them (  git add . && git commit -m “Commit Message”).

Let’s start with a real example.

We have a new project and want to append Git.

In project root, we execute this command :

 git init
We pressed the camera record button.

Then we start making changes. We add a file. We change the existing files. Any change we want.

Now it’s time to say camera, please save our records.

Execute these commands in command line :

git add . 
. means you want to stage all changes. If you want to add stage only a special file, you should execute this command with file name. git add specialfile.cpp

Then execute this :

git commit -m “Commit Message”
We saved recorded activities

* Hint: Don’t forget this, If you didn’t commit your changes, you don’t have any changes history if you lose it. Your history is as far as you committed them. No commit then no History. This is the rule.

Git holds your changes as a stack. Your each commit is an element of stack.

Stack Image

This is only for you to understand how to track your history. I mean, It’s not exactly like this. The real data structure of git is more than one. Actually it’s not a stack , I only want to imagine it. For better understanding.

Branches

Ok after we know what is git and why git, now we should find out what is branches. We talk about What git data structure is, and now we want to know how it works.

If you work with Gitlab or Github or Fork (desktop application only for windows and macOS), you see there is an option called Graph. If you click on it you see something like this:

Git log graph image
Git log graph
git log –graph
You can see graph with command line and you do not need a application or these sites.

It’s like a Graph. This part shows you commits and branches and how branches merged with others or how a branch starts from its own parent.

Now what is a branch? For example you want to travel from city A (Start Project) to city B (Release a version) with your friends (Co-workers). You and your friends start from a location (ex Last commit on branch master) and you agree that everyone will do one thing separately and return to the same location again and will mix up all things together. Everyone follows his own path and performs his task and returns to the previous location after finishing. The paths are equal to branches. Same location is your last commit on your master branch. And doing things is equal to commits on a branch.

Travel example
Git project example

* We will talk about what merge is and how many merges we have.

At the end we understood a series of things like pieces of a puzzle.

In the next article, we will give you an example of a real project so that these puzzle pieces can make a beautiful shape for you.