#4 Git’s file status lifecycle

On my system, there is one new directory having the name Git_Tutorial, when I right-click into that folder it gives me options, from the given options click on Git Bash Here. It’ll look like as shown below.

After clicking on Git Bash Here option you will get this command window there, in this command window we can perform git operations.

First I’ll run Git Status command to check whether the directory is already repository of git. If it’s not a repository of git then it’ll throw error as follows.

To make it a git repository we have to execute the following command i.e git init. and run git status. Because of the git init command git will create an empty repository. The hidden .git folder will be added to the Git_Tutorial folder.

Now, Git_Tutorial is initialized as an empty git repository, since we haven’t added any file into this it is showing a No commits yet message. If we create any file in this folder those files will be untracked. I have created the example.txt file into the Git_Tutorial folder and fired the git status command the result will be as followed.

Over here example.txt is untracked file and that’s why it is highlighted in red color. To track example.txt we have to fire following command.

git add --a

Above command will add all files into tracking area. To add particular file into tracking area we can use following command.

git add "filename"

Note: git add is a multipurpose command it adds files into Staging Area and Unmodified Area also.

Now example.txt is in Staging Area and Unmodified Area also. Suppose I modified example.txt then it will come from Unmodified Area to Modified Area as shown below.

As you can see in the figure example.txt is in Staging Area and Modified Area also. The example.txt in Staging Area contains an old version of the file while the example.txt in Modified Area contains our latest modification. If we commit our file at this point then the older version of file will be committed.

In order to commit the example.txt first we need to stage it. We will stage it using git add “example.txt”

Now, we can commit example.txt since it is in Staged Area.The command for commit is as follows

git commit -m "commit message"

Above command will commit the files those are present in Staging Area. Commit message should be meaningfull and to the point.

Leave a Comment

Your email address will not be published. Required fields are marked *