git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven’t, and which files aren’t being tracked by Git. Status output does not show you any information regarding the committed project history. For this, you need to use
List which files are staged, unstaged, and untracked.
git status command is a relatively straightforward command. It simply shows you what’s been going on with
git add and
git commit. Status messages also include relevant instructions for staging/unstaging files. Sample output showing the three main categories of a
git status call is included below:
Untracked files typically fall into two categories. They’re either files that have just been added to the project and haven’t been committed yet, or they’re compiled binaries like
.exe, etc. While it’s definitely beneficial to include the former in the
git status output, the latter can make it hard to see what’s actually going on in your repository.
For this reason, Git lets you completely ignore files by placing paths in a special file called
.gitignore. Any files that you’d like to ignore should be included on a separate line, and the * symbol can be used as a wildcard. For example, adding the following to a
.gitignore file in your project root will prevent compiled Python modules from appearing in
It’s good practice to check the state of your repository before committing changes so that you don’t accidentally commit something you don’t mean to. This example displays the repository status before and after staging and committing a snapshot:
# Edit hello.py git status # hello.py is listed under "Changes not staged for commit" git add hello.py git status # hello.py is listed under "Changes to be committed" git commit git status # nothing to commit (working directory clean)
The first status output will show the file as unstaged. The
git add action will be reflected in the second
git status, and the final status output will tell you that there is nothing to commit—the working directory matches the most recent commit. Some Git commands (e.g.,
git merge) require the working directory to be clean so that you don’t accidentally overwrite changes.