Skip to main content

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. When in doubt, run git status. This is always a good idea. The git status command only outputs information, it won't modify commits or changes in your local repository.

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.

In general, git status command provides the following information:

  • Where HEAD is pointing, whether that is a branch or a commit.
  • If there are any changed files in your current directory that have not yet been committed.
  • If changed files are staged or not.
  • If your current local branch is linked to a remote branch, then git status will tell you if your local branch is behind or ahead by any commits.
  • During merge conflicts, git status will also tell you exactly which files are the source of the conflict.

Git Status Syntax:

git status

Examples


1. When Working Tree is cleaned

To see how the git status looks like when there are no changes made run the following command in your terminal.

git status

Output:

On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)

2. 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.

touch hello-world.txt # Create a new file in the git repository
git status

Output:

On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
hello-world.txt
nothing added to commit but untracked files present (use "git add" to track)


As in the above output, it is suggesting to use the add command to track the file. Let's track the file and see the status after adding a file to the repository.

touch hello-world.txt
git add hello-world.txt
git status

Output:

On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello-world.txt


Next let's commit it and then check the status.

touch hello-world.txt
git add hello-world.txt
git commit -m "first commit"
git status

Output:

On branch master
nothing to commit, working tree clean

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


3. 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 and then run the status command:

git rm hello-world.txt # Delete a file from the git repository
git status

Output:

On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: hello-world.txt

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


You can learn more about the git status command and its options in git-scm's documentation.