# Behind the scenes of GIT

## what is .git folder ?

it is folder which git create when we initialize any project to track by th command \`git init\`. git use this folder to store all the commits, tags, blobs, tree , heads, branch any many other things to keep track our changes in files.

## what is inside .git/ ?

there are files and directory like

* HEAD
    
* refs/
    
* objects/
    
* hooks/
    
* info/
    
* logs/
    
* index
    
* config
    

## 1.Config

````markdown
 it is file for customization of repo like color, alias , remote etc.

```
# color customization
[user]
  name=some name
  email=some email
[color]
  ui=true
[color "branch"]
  local= cyan bold
  current= magenta
[color "diff"]
  old=add some color
  new=add another color

```
````

## 2.refs/

it is directory that store pointer of heads , tags, remotes .. etc.inside heads/ there are reference for latest commit-hash for branch like master, bugFix, darkMode, many other branches.

## 3.objcts/

The objects directory contains all the repo files. This is where Git stores the backups of files, the commits in a repo, and more. The files are all compressed and encrypted, so they won't look like much

### 4-types of GIT objects

```markdown
- commit
- blobs
- tree
- annotated tags
```

### Hashing Function

the function which map the inputs of arbitrary size into some fixed size output.

### Cryptographic Hashing :

1. ### One-way function which is infeasible to invert
    
2. ### Small change in input yields large change in the output
    
3. ### Deterministic - same input yields same output
    
4. ### Unlikely to find 2 outputs with same value
    

**Note:** **git use SHA-1 algorithm for hashing function which gives 40 characters hexadecimal number which is commit-hash, blobs-hash etc.**

## Git Database

Git is a key-value data store. We can insert any kind of content into a Git repository, and Git will hand us back a unique key we can later use to retrieve that content. These keys that we get back are SHA-1 checksums.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767703336811/d84204ba-83a9-44bb-8b2f-8404922d9308.png align="center")

### blobs:

Git blobs (binary large object) are the object type Git uses to store the contents of files in a given repository. Blobs don't even include the filenames of each file or any other data. They just store the contents of a file.

### Trees:

Trees are Git objects used to store the contents of a directory. Each tree contains pointers that can refer to blobs and to other trees. Each entry in a tree contains the SHA-1 hash of a blob or tree, as well as the mode, type, and filename.

### Some Commands:

* viewing trees : git cat-file -p master^{tree}
    
* git cat-file -t &lt;object-hash&gt; : tell about type of object like commit, blob, tree
    

### Commits:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767703621979/fb76863e-bdf3-4b45-8e3b-f5016f204850.png align="center")

Commit objects combine a tree object along with information about the context that led to the current tree. Commits store a reference to parent commit(s), the author, the committer, and of course the commit message!.

* every commit got reference to previous commit in parent:&lt;commit-hash&gt;
    
* we can see by using \`git cat-file -p &lt;commit-hash&gt;\`
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767703658013/ea517bc3-e3c0-4bf8-9645-ed3abdc1d319.png align="center")

### Some Terms :

* ### tree : structure of project while committing the project .
    
* ### blob : content store in file is blob.
    
* ### author:
    
* ### committer:
    
* ### message
    

**NOTE : everything is stored as hashed in objects directory so that git can retrieve data by the hashed key which is output of SHA-1 hashing function**

## Resources:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767703827245/2fea14be-98bc-4d03-a6c2-fc9647c1c4d6.png align="center")

[image-link-to-eraser](https://app.eraser.io/workspace/2tdTy9Hd2uQwgkLZNXW4?elements=xvsxkM58L4k_TVwJfGsyIg)
