Signup/Sign In

Git Status

Git Status is a command that displays the current status of our working directory and the staging area. It tells us what is happening in our Git repository and also tells us what should we do next. It is probably the easiest and one of the most frequently used commands.

What does Git Status do?

  • Git Status is a simple command that tells us the state of our repository.

  • It gives us information about files that have not been committed yet. These can untracked files, unstaged files, or staged files.

  • It also gives information about the current branch and even indicates the files where a merge conflict has occurred.

  • Git Status also tells us the next commands that we should use for different purposes.

  • However, Git Status will not show the commit history and any other information about the commits.

  • Any files that are specified in the .gitignore file are also not displayed by Git Status because they are ignored or not tracked by Git at all.

Git Status Illustration

Git Status Command

In most cases, Git Status will be used without any additional options or flags.

$ git status

The output of the Git Status command can be obtained in a shorter form by using the -s flag with it. This will just return the names of the files that have changed.

$ git status -s 

By default, Git Status will not show any ignored files but we can still view them by using the --ignored option.

Git Status Output

Let’s take a look at scenarios and the output that Git Status gives us in these scenarios.

Consider that we have just created a repository and created a new file called a.txt. Git Status will tell us that this file is untracked. The output for this case will be:

Untracked files shown by Git Status

Now we add that file to the staging area. Now it will tell us that there are changes to be committed for that particular file because the file has been staged.

Staged Files shown by Git Status

Next, if we modify this file then Git Status will tell us about the two versions of the file - one that was added to the staging area and one that we just modified(Unstaged).

Staged and Unstaged Files shown by Git Status

In all of the above cases, Git Status will show us the branch on which we are working and also tell us that we have not made any commits yet. This line will get removed when we add a commit.

Now let’s create a merge conflict and see the output of the Git Status command. It shows that we have unmerged paths and also tells us the file name where conflict has occurred. It also tells us the commands we can use to resolve it.

Merge Conflict and conflicting files are also displayed by Git Status

Summary

Git Status is a command that won’t change our repository but gives us valuable information about what is happening in our repository. It is a very simple command and in most cases, won’t even require additional flags or options. I hope that this tutorial will help you understand what Git Status does and how it helps us in understanding our files in a better way.