Analytics Vidhya
Published in

Analytics Vidhya

Git Part 2: The Three Worlds System

Today we take a look at Git and why the staging area is very useful.

Photo by Phil Botha on Unsplash

Today there are lots of different version control systems. One of the most famous is Git. But what are the reasons? How did Git manage to stand out? One important cause will be discussed today.

Agenda

  • 3 Layer-System
  • Benefit of the Staging Area
  • Conclusion

3 Layer-System

Git consists of three areas. Below you can see their names and order. First, we’ll try to get an idea of how they work.

https://git-scm.com/book/en/v2/images/areas.png

Working Directory
On the working directory, we have a single uncompressed version of the project. So we can make modifications and add new features. Besides, changes in the working directory are marked, but not stored in the Git database. If we lose changes, it’s not possible to restore them. Below is an overview of the flagged changed files.

Staging Area
The second layer is called the staging area or index. As soon as we move changes from the working tree to the staging area, we store a snapshot of all the changes to the files in the Git database. Files that we don’t change are only referenced. The corresponding command is git add filename. Or if you want to save all changes, you can use the wildcard. To do this, you must replace the filename with the dotted character. The changes are not saved permanently. All changes that aren’t committed to the git directory within a certain period are removed by the garbage collector. To see the status of the staging area, as well as the status of the working area as above, we need to type the command git status.

Git Directory
The last part is the Git directory. This is where the snapshots are stored permanently in the Git database. Additionally, all saved changes are linked to the project history. To do this we have to commit the changes from our staging area -> git commit -m "description".

Benefit of the staging area

Most version control systems consist of a 2-layer system. One reason for Git to stand out is the layer between them. But why? What is the advantage?

In my mind, the greatest benefit is the control over what we want to commit to our git directory. In other version control systems, we simply store all the changes we have made. But in Git, it’s a bit different. Here, we can make changes and later decide which files we want to store group. We have commands like git reset, git stash, git commit -p and much more. So we can build our commits completely free. If you have additional benefits, it would be great to leave them in the comments.

Conclusion

Today we took a look at Git’s 3-layer system. In the end, you should know the differences between the layers and what they are used for. We also talked about the benefit of the staging area. If you have any questions or feedback, please let me know in the comments. See you soon.

In my following article, we will do an exciting tour through the .git directory. Buckle up and let’s go -> Discover the .git Folder.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store