Skip to main content

Command Palette

Search for a command to run...

Inside Git :How it works and the role of .git folder

Published
2 min read

Before get into the how git works,let’s first understand what is git?

Git:-

  • Git is a distributed version control system (VCS).

  • Git is used to track live changes inside the code,for collaboration.

  • It is termed as VCS because it allows a multiple people to work on the same branches.

Now intialize a git into your project with command:

git init

With git init command .git folder created in your project ,we should not manipulated this folder because it is maintained by itself.

.git folder:-

  • The .git folder is a hidden directory which contains metadata and history of your project.

  • It stores everything commit history, file versions, tags and branches.

  • Deleting this folder means losing your local project’s entire history.

Git Objects:-

A fundamental building block of the git repository, used to store data as a specific type (blob,tree, commit or tag)

Four main git objects:-

  1. Blob:-

    1. Stores the raw content of a file.

    2. It does not store metadata like filename,date and author.

    3. It only contains the files data at a specific point in a time.

    4. If two files have identical content,git stores only one blob.

  2. Tree:-

    A tree is an object that represents a folder.

    1. Names of files

    2. Names of folder

    3. Hash

  3. Commit:-

    A commit is a saved snapshot of your project at a specific time.Identified by unique ID i.e Hash.

    1. Author

    2. Timestamp

    3. Commit message

  4. Tag:-

    In git, a tag is uesd to mark specific commit-most commomally to label releases like v1.0, v2.1.3

How git track changes:-

Git tracks changes saving snapshots of files, not by tracking line-by-line edits.

* On the next commit:-

  1. Git takes snapshot of all files.

  2. If a file changes,git stores a new version.

  3. Each commit links to the previous one.

Conclusion:-

Git is a distributes version control system which tracks the live changes inside the code, collaborate efficiently,git tracks changes saving snapshots of files, not by tracking line-by-line edits.Git compares each commit to previous commit to track the change. It works by storing the snapshots of project inside the .git folder which is a hidden directory which uses a core objects like blob,tree and commit.