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.
The Git Status command shows the state of the working directory and the staging area. It allows you to see staged changes and the files that aren’t being tracked by Git. The Status output does not display any information about the committed project history. For this purpose, use the git log 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:
$ git status
Output:
On branch master
nothing to commit, working tree clean
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:
$ touch cloudnclear.txt
$git status
Output:
On branch master
Untracked files:
(use “git add <file>…” to include what will be commited)
cloudnclear.txt
nothing added to commit but untracked file present (use “git add” to track)
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 add cloudnclear.txt
$git status
Output:
On branch master
Changes to be commited:
(use “git restore –staged <file>… ” to unstage)
new file : cloudnclear.txt
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
Output:
On branch master
nothing to commit, working tree clean
Git 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:
$ git rm < File Name>
The above command will delete the specified file from the repository. Now, check the status of the repository. Consider the below output:
$git rm cloudnclear.txt
$git status
Output:
On branch master
Changes to be commited:
(use “git restore –staged <file>… ” to unstage)
deleted : cloudnclear.txt
The current status of the repository has been updated as deleted. This is all about git status command.
Ignoring Files in Git Status:
Untracked files can be of two types: ones that have not been added and committed to the project and the ones that are binaries like .pyc, .obj, .exe, etc. If binaries are included in git status output, you cannot see the actual state of your repository. Thus, Git puts paths in the .gitignore file to ignore these files. The ones that you do not want to ignore, will be included on a separate line. The * symbol is used as a wildcard:
For example:
*.obj
*.jpeg
For more Git Related post click here.
- Git init Command
- Git add Command
- Git Commit Command
- Git Clone Command
- Git Config Command
- Git Alias Command
- Git Checkout Command
- Git Pull Command
- Git Push Command
- Git Fetch Command
- Git Revert Command
- Git Remove (rm) Command
- Git LOG Command
- Git Cheat Sheet
Happy Learning !!