Skip to main content

Command Palette

Search for a command to run...

Inside Git: How It Works and the Role of the .git Folder

Updated
3 min read

Introduction

Git is tool, It use track files and especially code of the project. It type of VCS (version control system) and it allow developer contribute the project, even if they are not connected common server. It developed by Linus Torvalds in 2005 when he was developing Linux kernal at time he was developed git mean version control system.

Git is Open Source nature and it code openly available and maintained. modify by global community and It work under GPL (General Public License). Git complete workflow discuss in the article. And Git softwere host by github.

What is Git and How it Works

Git is Softwere, it is used to track changes in code and It track what changes developer make in the source code. It track complete changes history. Think as entire timeline of your project from beginning to end.

First of all we are create new project mean new repository and initialize git use git init command. And after that developer writing code and create new file in the project. Then developer complete or add new features. Then developer type new command in IDE (like.VsCode) terminal git add <file name> or developer want all code save then developer type new command git add . . After that all changes save in stageing area and code read for next command and then developer changes save permanently use git commit -m “message” command after that all changes save permanently. and developer exit the Editor.

Command step

  • Initialize project mean create .git folder use git init cmd.

  • Show all tracked and untracked file use git status cmd.

  • Change save in staging area use git add . or git add <fileName>.

  • All changes save permanently then use git commit -m “message“.

  • Show all commit with detail use git log .

The .git Folder : Heart of a Git Repository

You are use git before probably familiar with .git folder. This folder contain all information that need track history.

Your are create new Folder after that you are initialize git use git init command. Then automatic create new .git/ Folder. In this folder store many folder and file like config, description, HEAD, hooks/, info/ objects/ refs/.

Internal Structuer of the .git Folder

All Folder and File store many information. Anycase .git/ folder remove then all Source Code history remove. Because .git Folder is hide in our project

Folder And File

  • config : In this file store project all config information like filemode createdAt and etc. info. store

  • description : In this file store all about project description.

  • HEAD : In this file store reference of brach.

  • hooks/ : In this folder store many hooks mean function. Work together and perform task mean track history.

  • info/ : In this folder store information.

  • objects/ : Store file data commits and trees.

  • refs/ : store branch and tags record.

How Git stores Commit and History

Git use internal workflow and store commit and History. Commit mean snapshot of your project at a point in time and Commit store in .git/objects file.

Git uses internally 4 objects :

  1. Blob

  2. Tree

  3. Commit

  4. Tag

We are type git commit -m “msg” after that staging area content convert blob + tree. after that tree use object and create floder structure and then finaly create commit object Which store commit.

History Track Mechanism Git store parent refs with every commit. And this Mechanism store git history. User can show our commit history using git log command.

Conclusion

Git is Softwere or tool. It implementation very easy and fast. Developer can initialize git in every project or folder. Git softwere hosted by Github. Github is server which host git and then developer push code on github server and then contribute every single developer.

thanks.