Make Selenium Easy

Git Tutorial 5 – Know The State Of Working Directory – git status

Introduction

As a part of GIT Tutorials End To End, we will learn about a frequently used git command “git status“.

We already know that how can we convert an existing unversioned directory or create a new git directory from this tutorial. Before we learn more about the git status command let’s perform some steps.

Did you know that I have started a YouTube channel as well and I need your support to make it successful. Please do watch content then comment, like, share, and obviously subscribe.

What is git status?

  1. Create an empty directory.
  2. Right-click and click on Git Bash Here.
  3. Type a git command as “git status”.
  4. Type a git command as “git init“.
  5. Type “git status” command again.

You can observe “git status” commands displays a proper response after we ran git init. It displays that we are currently on the master branch. There are no commits yet and there is nothing to commit as well. It also suggests you create or copy files and use git add to track. Don’t worry if you did not understand anything.

Let’s create an empty text file and rerun the git status command. We can use a UNIX command “touch <fileName>” to create an empty file as shown below.

Now you can see that the command “git status” shows that there are untracked files. Did you get what is actually done by the git status command? It displays the state of the working directory or of the branch where you are currently working. It lists which files are staged, unstaged, and untracked. However, the above output will be changing based on the situation which we will see in upcoming posts.

Untracked files are files that are present in the working directory but have not been added to the repo’s tracking index. In short, git is not tracking any changes to those files till we explicitly add them using the git add command.

With little knowledge about the “git add” command let’s use it. Use “git add <fileName>” and rerun the “git status” command.

Now you can see we see different information. When we add a new file that time it was untracked. After running the “git add” command file status moved to “changes to be committed“. It is also called file is staged for commit or file is in a staging area.

Let’s perform an extra step. Just follow as of now. Run another git command “git commit -m “myFile1 committed” ” followed by the “git status” command.

Now you can see the response of git status is somewhat similar to the first time run. We have already done a commit so it is not showing the “No commits yet” message. It is not showing to create and add files to track as that is also done and GIT knows we are not new to this now. Working tree clean means there is no change in the state of the working directory.

Let’s understand more about the git status command. If I give you a document and asks you to find what has changed. You are required to compare the document from another document or if you know what has been changed. In short, you need to compare. In the above examples with whom git status was comparing to let us know that something has changed and after adding and committing those changes were not shown as part of git status command.

When we run git init command a .git folder is created. Inside .git folder we have a file named HEAD which points out the last commit or tip in the current checkout branch. As we have only and default branch called master here so it will be a point to the tip of the master branch. Let’s see the content of the HEAD file.

So when we run git status commands then it actually compares what has changed from the last commit of the currently checked-out branch.

From official git status documentation:-

  1. Displays paths that have differences between the index file (Staging) and the current HEAD commit. We need to run the git commit command here.
  2. Displays paths that have differences between the working tree and the index file. We need to run git add followed by git commit here.
  3. Displays paths in the working tree that are not tracked by Git (and are not ignored by .gitignore). Here also We need to run git add followed by git commit here.

The git status command is a safe command and nothing changes.

Please subscribe to my YouTube channel Retarget Common to learn from my video tutorials.

Below are important end to end tutorials for Testers:-

Selenium Tutorials

Rest Assured Tutorials

Postman Tutorials

TestNG Tutorials

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Git Tutorial 5 – Know The State Of Working Directory – git status

by Amod Mahajan time to read: 3 min
0
%d bloggers like this: