Git Status
This is mostly used to check whether changes and files are tracked between git add and git commit.
Cleaning the Working Tree
This is what the git status looks like when there are no changes. To check the status, open git bash and run status.
$ git status Output:
The working tree has nothing to track or untrack, so the output shows a clean working tree.
New file status
When we create a file, the state of the repository changes. Let’s create a file with touch. Now, check the status with status.
According to the above output, there’s nothing added to commit, but untracked files are there (use git add to track).
Let’s track the file and see the status after adding it to the repository. Run the add command to track the file.
We can see in the above output that the status after staging the file is “changes to be committed“.
We can check the status before committing blindly. This command will help us avoid changes we don’t want to commit. Let’s commit and then check the status.
After committing the file, it’s still clean.
Modification status of existing files
Here’s what happens when an existing file gets modified. Run echo as follows:
$ echo "Text"> Filename Check the status of the repository now that the text has been added to the specified file:
As you can see in the output below, the updated file is untracked. It is red because it hasn’t been staged yet. When it is staged, its color will change to green.
Deleted file status
Check what happens when a file is deleted from the repository. To delete a file, run the following command:
$ git rm < File Name> If you run the above command, it will delete the file from the repository. Now check the status of the repository.
Repository status has been updated to deleted.