How Git Works – The theory behind it

Let’s talk about how Git actually works, in order to use Git for your project. First of all, you have to initialize it. This will help you to learn how git works in a practical way. Imagine you have a folder called my website and in this folder, you have stored all of your files like index.html, style.css, and also we have a folder for images. So, when you will initialize Git there will be created a folder named “.git”. So, once this folder is created than the entire directory where this folder is placed, it will become a repository. 

What is Repository?

A repository is a container for a project which you want to track with Git. Repository is like a folder in your personal computer but this folder in on the cloud. This folder is used to store your projects all files and folders.

Track changes of your Project

How Git works

Alright, after that we are able to track the all changes of our project. If doesn’t matter if we changes things inside the images folder or inside .git folder, all the changes will be recognized by the Git.

Remember if the Git initialization happed in the images folder, then changes outside of the images folder with not be tracked because in that case, the repository is going to be images folder, not the entire project.

READ MORE What is Version Control?

How Git works

Suppose that we added a new file to our project. Let’s say script.js and we want to send this version of our project in history. We can do that using commit which actually allows you to take a snapshot and set the current state of the project. People do a lot of research on how git works but remember you can learn this by doing practically.

Example with Diagram

How Git works

Imagine the line in the above figure represents the history or sometimes it’s called a timeline of the project and before we take the snapshot or commit something, we are at the starting point. After doing some work, suppose that we want to take the snapshot and save the current state of the project.

For that, we have to make a commit and after that, let’s say we added some JavaScript to our project and made the website dynamic and created another commit. Now we have already saved two versions of our project.

Assume that we added some back-end functionality to our project and take another snapshot. So, overall we created the history of the development of the project, and anytime in the feature, we are able to go back in time and get a previous state of the project we want.

Remember the line we mentioned is also called a branch. To be precise, it’s a master branch. In general, you are able to work on different branches.

If you like this article about how git works than share it with your friends on Facebook, Twitter, etc.

Muzammal Ahmad

I am an Ethical Hacker, Programmer, and SEO (Search Engine Optimization) expert. I love to write blogs and share knowledge with people. I also like to help people to solve their technical or internet relates problems.

Leave a Reply

Your email address will not be published. Required fields are marked *