4 Areas of GIT
DevOps Introduction to Git
If you would like to become an expert in DevOps then mastering Git (version control system) is a must, but knowing the history and few commands is still not enough. It’s of primary importance to acknowledge the reasons why Git is worth all the efforts, how the command works; what happens when we run the git commands.
4 Git Areas
So, let’s understand the four areas of git that are Out of Git, Working Directoy, Index area and .git Directory. As many of you might not be familiar with these areas and the mechanism behind them,
The four areas of Git:
- Out of Git/Stash: Temporary storage area/like a clipboard
- Working Directory: It contains files you are currently working on — use, change or modify them.
- Index Area: This is the intermediate area that stores information about what will go into your next commit; files here are staged (e.g. ready to be recorded).
- .git Directory: The Git Directory that stores all states of your project you recorded, also known as commits — particular points, recorded as the project’s states in the history of Git.
File Statues
Workflow in four areas
Understanding how git works when we pass various commands or how data/files move in various directions:
Left to right -
When we talk about moving from left to right we talk about three things: edit the file, stage the file and commit the file. So we move the data from the working directory to the index and then to the .git repository.
Starting with the Working Area, it is the area where our files/data are currently present. When we make any changes to our files, the changes remain intact in the working area. If we check the status using git status
$ git statusGit says, Changes not staged for commit. The message itself says that in order to commit, we first need to stage the changes.
In order to stage the changes, we run
$ git addNow the changes are status, let’s check the status
$ git statusGit status tells that the file is modified and Changes to be committed. We can also verify if the files are staged by checking the difference between the working area and Index area using command git diff. In the above screenshot, we see no result of the command git diff because there is no difference to show.
We can also check the difference between the Index and Repository using git diff --cached
$ git diff --cachedNow in order to move the files from the index(staging area) to the git repository, we run git commit
-m: m stands for the message, we can pass the message to the commit we are doing
Get Arya Madhur’s stories in your inbox
Join Medium for free to get updates from this writer.
As soon as we commit the updated file is added to the repository. And all three areas contain the same data.
Right to left -
When we talk about moving from right to left here we talk about moving the data from repository to index and then to the working area.
We use the command checkout, it does two things. It changes the repository first and then moves data.
- In the repository, it moves the header reference, generally to another branch, so it changes the current commit.
- And the second thing it does takes data from the new commit, and it copies the data from the repository to the working area and the index.
In the above image when we checkout him then the head moves to his branch. The current commit is changed to him and copied the data to the index and working area
$ git rm --cached himIt will unstage the file and remove it from the index.
$ rm himIt will delete the file from the working area.
So till now, we discussed the functionality of Working area, Index area, Repository of git. Let's cover the fourth area that is stash.
The Stash -
We use git stash to store changes that are not ready to be committed and that meantime we need to change our branch in order to carry out some other work.
$ git stash applyIn the above image, we can see all the data in the working area and index which we wish to put aside in stash for some time.
So to save the changes in stash use the below command. It will take all the data from the working area and index that is not in the current commit in the repository.
$ git stash saveor
$ git stash --include-untrackedIt will store all the untracked files by default
In the image below, we can see that our file chess.txt is not available as it is now successfully stored in the stash area.
Now let’s check our chess.txt is present in the stash area use the command
$ stash listIn the above image, we have only one element so it is stash@{0}
Now to get all our data in the working area and the index area back where it was before we stashed it. Use the below command
$ git stash applyor
$ git stash apply --indexwhen there are multiple stashes
We can conclude Stash is like a clipboard; it is a place where it stores the stuff that needs to be set aside for some time.
Here we finished with the stash area. Hope you have a better understanding of Git working areas and their workflow.
Thank you for reading!




