Javatpoint Logo
Javatpoint Logo

Git Status

The git status command is used to display the state of the repository and staging area. It allows us to see the tracked, untracked files and changes. This command will not show any commit records or information.

Mostly, it is used to display the state between Git Add and Git commit command. We can check whether the changes and files are tracked or not.

Let's understand the different states of status command.

Status when Working Tree is cleaned

Before starting with git status command, let's see how the git status looks like when there are no changes made. To check the status, open the git bash, and run the status command on your desired directory. It will run as follows:

Output:

Git Status

Since there is nothing to track or untrack in the working tree, so the output is showing as the working tree is clean.

Status when a new file is created

When we create a file in the repository, the state of the repository changes. Let's create a file using the touch command. Now, check the status using the status command. Consider the below output:

Git Status

As we can see from the above output, the status is showing as "nothing added to commit but untracked files present (use "git add" to track)". The status command also displays the suggestions. As in the above output, it is suggesting to use the add command to track the file.

Let's track the file and will see the status after adding a file to the repository. To track the file, run the add command. Consider the below output:

Git Status

From the above output, we can see that the status after staging the file is showing as "changes to be committed".

Before committing blindly, we can check the status. This command will help us to avoid the changes that we don't want to commit. Let's commit it and then check the status. Consider the below output:

Git Status

We can see that the current status after committing the file is clean as it was before.

Status when an existing file is modified

Let's check the status when an existing file is modified. To modify file, run the echo command as follows:

The above command will add the text to the specified file, now check the status of the repository. Consider the below output:

Git Status

We can see that the updated file is displayed as untracked files. It is shown in red color because it is not staged yet. When it will stage, its color will change to Green. Consider the below output:

Git Status

Status when a file is deleted

Let's check the status when a file is deleted from the repository. To delete a file from the repository, run the rm command as follows:

The above command will delete the specified file from the repository. Now, check the status of the repository. Consider the below output:

Git Status

The current status of the repository has been updated as deleted.


Next TopicGit Branch





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA