Git status Command with Examples

git status command

Git status command shows the state of files in your project. It shows files in the staged area, files not yet staged, and files not tracked by Git.

It also shows which branch you use at the moment and if you have changes to commit. You can run it many times to see updates after you add or reset files.

Understand the git status Command

Git status command shows what files Git will commit and what files Git does not track yet. It does not change the files but only shows their state. It helps you know what to do before you commit.

You can use this command often to see what files are ready for the next commit.

Here is the command:

git status

This command shows your current branch name at the top. It then shows two lists. The first list has files in the staged area. The second list has files that you changed but did not stage yet. At the end, it shows files Git does not track at all.

Staged files are ready for commit. Unstaged files are changed but not yet added. Untracked files are new files outside Git.

The Difference Between git status Short and Long output

Git status has two types of output. The long output is the default one you see when you run git status with no flags.

It shows branch, staged files, unstaged files, and untracked files in full detail.

The short output shows less detail in a compact form. You get it with the -s or --short flag. It shows a two-letter code near each file.

The first letter shows staged status and the second letter shows unstaged status. This is faster to read when you work on many files.

Here is the command:

git status
git status -s

You can use the long output when you want full detail about file states. You can use the short output when you only need quick info on file changes.

Examples

Show status of files in a new repository:

git status

This example runs git status in a new repository. It shows the current branch name. It shows that no commits exist yet.

Stage a file and see the change:

git add index.html
git status

This example stages a file with git add. Then it runs git status. The output shows the file index.html in the staged area, ready for commit. It also shows other files still not staged.

Use short output for quick checks:

git status -s

This example uses the short output. It shows each file with a two-letter code. It is useful when you have many files and need a quick view of changes.

Mix staged and unstaged files:

git add app.js
git status

This example stages app.js but leaves style.css unstaged. Git status shows app.js in the staged area. It shows style.css as changed but not yet staged. You can now decide to stage or discard it.

Wrapping Up

You learned how git status shows file states and how you can use both long and short output to track changes.

Here is a quick recap:

  • Run git status to see the branch and file states, use git status -s for a compact view, and stage or unstage files based on what the command shows.

FAQs

What is the use of git status command in Git?

git status command shows the current state of the working directory. It displays:
  • Untracked files that are not staged
  • Changes staged for commit
  • Changes not staged yet
Example:
git status

How do you check staged and unstaged changes with git status?

Run git status in your repository. Output explains both:
  • Changes to be committed → Staged changes
  • Changes not staged for commit → Modified files not staged
Example:
git add file1.txt  
git status

What is the difference between git status and git status -s?

git status gives a detailed description. git status -s or git status --short gives a short view.
  • M → Modified
  • A → Added
  • ?? → Untracked
Example:
git status -s

How to fix untracked files shown in git status?

You can add or ignore untracked files.
  • Track files with
    git add filename
  • Ignore files by adding them in .gitignore
Check again with:
git status

Similar Reads

Git add Command with Step by Step with Example

The Git add command places new or changed files into the staging area so you can prepare them for the…

Git Introduction: Git and GitHub Explained Guide

If you're diving into coding, your introduction to Git and GitHub will happen in no time. Git's your personal time…

How to Delete a Branch Locally in Git

You sometimes need to remove old or unneeded branches locally in Git. You might want to keep your project clean…

How to Switch Branches in Git: git switch vs checkout

The switch operation in Git will make it easier. Designed to simplify the process for developers, it's safer and more…

Git config Command: A Complete Tutorial to Configure Git Settings

You can use the Git config command to set user data and control Git behavior. It saves preferences for projects…

Git Push: A Step-by-Step to Syncing Your Local Repository

The purpose of the Git Push command is to upload local repository changes to a remote repository. Pushing your committed…

Git Pull Force: Safely Overwrite Local Changes

If you've worked on any coding project, you would know this frustrating wall where Git simply refuses to pull the…

What is Version Control System? Software List Explained

One of the tools we need for software development is a Version Control System. It tracks code changes, making a…

Git List Branches: How to Show All Local & Remote Branches

You can use Git to show all branches or use branch-related commands to list branches and their status. This helps…

Git Pull: How to Keep Your Code in Sync

When you work on a project with friends, one writes the intro, one adds pictures, and others handle different parts.…

Previous Article

JavaScript toString Function: How it Works with Examples

Next Article

PHP array_merge_recursive: Merge Arrays Deeply

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.