Git Status Command

The git status command allows you to view the current state of files and changes to your working directory and staging area. This lets you see which changes have been staged and which haven’t and also displays any files that Git is not tracking.

Git Status only shows you information about the current state of your project, but if you try to get the information about committed project history, then it will not show any information about that. For that, you need to use the git log command.

Post On:GIT Status Command
Post Type:GIT Tutorial
Published On:www.softwaretestingo.com
Applicable For:Freshers & Experience
Get Updates:Join Our Telegram Group

This git status command is a lifesaver for developers! It helps them keep track of our uncommitted changes and understand how our project files are being tracked. In this post, we’ll explore this amazing command in-depth and learn how to use it effectively to understand your file statuses.

Git Status Command

The git status command is useful for seeing which changes or files have been added to the staging area and which haven’t yet been committed. If a file has not been added yet, then you can use the git add command to add your changes or files to the staging area, and similarly, if the changes are not yet committed, then you can use the git commit command to commit those changes in the commit history.

From our previous article, we learned that the Git command works with three different trees. These are the working directory, staging area, and commit history. If you’re unfamiliar with these concepts, more information is available on this topic. The status command primarily uses the first two trees: the working directory and staging area.

What Does the Status Command Actually Tell Us?

When we are using the git status command, it will share with us information like:

  • What changes you’ve made to your working directory?
  • What are the changes that are present in your staging area?
  • Which of your files is actually being tracked by Git?

With the above information, when we run the git status command, it also shares the information on the status of the files or changes because the files are available in the repository in any of the 3 statuses: untracked, no-history, or modified.

Git Status When Working Tree is Cleaned

When you’re working with git, it’s important to regularly check your project’s status to ensure that everything is up-to-date. The best way to do this is by running the “git status” command on your desired directory. This will give you a quick overview of what changes are made to the files in that directory and the status of those changes (i.e., whether they’re committed, staged for commit, or just waiting for you to review them).

Git Status-Working Tree Clean

Git Status: Untracked State

Let us create a file inside the project directory by executing the touch command, and after that, if you run the git status command, then you can notice the file name in red color.

Git Status-Untracked State 1

If you read the message of Git bash, you can notice the current status of the file is untracked, and it is also displaying in red color. This means the changes or files are not yet tracked by Git. When we initialize a git repository, all our files are in that state only.

If you want to track those files of your project, then you have to use the Git add command, and after adding the file to track, if you run the git status command, then it will display in the green color.

Git Status-Untracked State 2

Git Status when an existing file is Modified

Here, we will see the file’s status when its content is modified. For this, we are going to modify a file using the echo command.

notepad <file name with extension>

Or you can use the below command

echo “Text”> Filename  

Git Status-Modified File

Note: As Notepad is configured as the default editor for Git, when we execute the Notepad command, it will open the mentioned file in the editor, and you can add or update the contents of the file. After that, you can save and close.

After running the above command, check the status of the file by executing the git status command. You can notice that modified is mentioned before the file name, and the color of the file name is displayed in red. Because the file is not added to the staging area, and once the file is added into the staging area, it will be displayed in green color.

Git Status-Modified File and Add

Git Status when the file is Deleted

To delete a file, we can use the rm command. You can write the command below:

rm <file name with extension>

After removing the file, you can check the status by running the git status command.

Git Status-File Deleted

Conclusion:

This article discusses the git status command, what it is, when to use it, and how to get the most out of it. Git status is a crucial tool for developers – keep reading to make sure you know everything there is to know about it!

Categories GIT
Avatar for Softwaretestingo Editorial Board

I love open-source technologies and am very passionate about software development. I like to share my knowledge with others, especially on technology that's why I have given all the examples as simple as possible to understand for beginners. All the code posted on my blog is developed, compiled, and tested in my development environment. If you find any mistakes or bugs, Please drop an email to softwaretestingo.com@gmail.com, or You can join me on Linkedin.

Leave a Comment