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 are not being tracked by Git.
Git Status only shows you the 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|
|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 ones haven’t been committed yet. So that if a file is not 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 not familiar with these concepts, there is more information available on this topic. The status command primarily uses the first two trees; these being 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 like untracked, no-history, or modified.
Git Status When Working Tree is Cleaned
When you’re working with git, it’s important to regularly check the status of your project in order to make sure 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, as well as the status of those changes (i.e. whether they’re committed, staged for commit, or just waiting for you to review them).
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.
If you read the message of Git bash you can notice the current status of the file is untracked and also it is displaying in the 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 git 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 when an existing file is Modified
Here we are going to see the status of the file 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
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 then it will be displayed in green color.
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.
In this article, we’re discussing 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!