Another GIT Introduction - part 1
Tags: git, introduction, newbie
Published: 2020-04-16 07:29:46

<i>I'm posting here a series of introductory articles I wrote on another platform, hoping you will enjoy them<i> 


The main difference from GIT and other control versioning systems _-Subversion for example -_ is the way it thinks about its data. What usually happens with other systems is that they store data as a set of files and the changes made on each file over time, while GIT thinks about its data as a series of snapshots of a mini filesystem.

![svn manages changes](https://raw.github.com/wildeng/articles-images/master/svn-manages-changes.png)
*How a Subversion style system manages changes*

This means that every time you commit, it takes a picture of your project at that moment and saves a reference to it and. As a matter of efficiency, if a file has not been changed, it saves only a link to the previous file.

![svn manages changes](https://raw.github.com/wildeng/articles-images/master/git-manages-changes.png)
*How GIT manages changes*

Another important fact about GIT is that almost every operation is local and generally, you do not need to go online because the entire history of your project is stored locally. Because of this, most of the operations seems instantaneous.


#### GIT states and terminology

GIT workflow is based on three main states:

1. <b><i>Committed</i></b>: data is safely stored in your local database.
2. <b><i>Modified</i></b>: you changed your files but they are not yet added to your local database.
3. <b><i>Staged</i></b>: you marked a file in the current version to go into the next commit.

Following the previous definitions, three main working areas can be identified:

1. <b><i>GIT directory</i></b>: where GIT stores the metadata and the database for your project.
2. <b><i>Staging area</i></b>: this is a simple file, saved in the GIT directory, where GIT stores all the informations on what will go into your next commit.
3. <b><i>Working directory</i></b>: this is a single checkout of one version the project. The files are pulled out of the GIT directory and placed on disk for you to modify.

![svn manages changes](https://raw.github.com/wildeng/articles-images/master/git-main-areas.png)
*GIT main areas*

From the picture above we can define how a typical GIT workflow looks like:

* You modify the files in your working directory.
* You stage them, adding a snapshot in the staging area
* You perform a commit which takes the snapshot from your staging area and stores it permanently in your GIT directory.


#### GIT Objects

What is the real heart of a GIT repository and which kind of objects GIT stores?

The <b><i>object store</i></b> is the correct answer, a database that holds four kind of items: <i>blobs, trees, commits and tags</>.

<b><i>Blobs</i></b> are a string of bytes with no further internal representation, as far as GIT is concerned. This does not mean that its implementation is simple. Every version of a file in GIT is represented with a blob where the entire content of the file is contained. If on one side this means occupying more space on disk, on the other side has the advantage of preventing corruption. If this happens on a blob, future versions of the file are not affected by it.

A <b><i>Tree</i></b> represents a portion of the repository content at one point in time, a snapshot of a particular directory all its children included.

A <b><i>Commit</i></b> is a snapshot of the entire repository content with additional data like identifying content such as author's name or committer's info, relationship of this state with all the other recorded states, providing an evolution of the repository over time.

Specifically it is composed by:

* A pointer to a tree containing the complete state of the repository at one point in time.
* Author and committer information plus time and date the changes have been introduced.
* A list of zero or more objects, parents of the current commit.

A <b><i>Tag</i></b> is basically a commit with a human readable name in a namespace reserved for this purpose.

It consists of:

* Name of the person making the tag
* A timestamp
* A reference to the tagged commit
* A free-form text message

Hopefully you will now have appreciate the clever engineering that lies behind GIT curtains and also have a basic understanding of how it works.

In the next posts I will try to explain some other related GIT arguments that I found useful and interesting like rewriting history. I will also share some nice and useful GIT commands I use day by day.

Enjoy!