Sitemap
DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.

Deep Dive into GIT

--

GIT is a distributed version control system that tracks computer file changes over time. It was initially designed and developed by Linus Torvalds for Linux kernel development. He wanted to create a distributed version control system that would be fast and efficient, yet provide high availability. Git became very popular among other developers as it allowed for the branching of projects and easy merging of code from one branch to another.

Get Ravi Chandola’s stories in your inbox

Join Medium for free to get updates from this writer.

In this blog, we are more concerned about the areas of git which helps our code to push from different stages. Before moving code to the repository, it should traverse from the Working area to the Staging area.

Press enter or click to view image in full size

The working area is the scratch space, where you can add, modify and delete the content. The files not in the staging area, will not be handled by the git and those files are called untracked files. So in the short working area is nothing but your local directory.

Staging Area

The staging area is something where git knows the change between the current and the next commit. A clean staging area isn’t empty, the baseline staging area is a copy of your latest commit. So it contains, a list of files in your last commit as well as the SHA1 hash of those files as they were in the last commit. The way it stores the information is through the index, the index is the binary file in the .git directory.

When you add, rename, and remove the files from the staging area. Git knows because of the SHA1 of the changed files that were in the repository.

In order to look at our index

git ls -files -s

Moving Files IN and OUT of Staging Area

  1. Add files to commit
git add file.txt

#git add <filename>

2. Delete this file in the next commit

git rm file.txt

Let's see how your code traverses from Working Area to Staging and then from Staging Area to Repository.

Traverse of files from different areas
git add readme.md
git commit -m "Readme.md contains information"
git push

--

--