What is git status?


The git status command in Git is used to display the current state of the working directory and the staging area. It shows you what changes have been made in your project, whether they are staged for commit, not yet staged, or completely untracked.

What git status Displays:

  1. Untracked Files:

    • These are files that exist in your working directory but are not tracked by Git (i.e., they have never been added to the repository).
    • You can add untracked files using:

      git add <filename>
      
  2. Modified Files:

    • These are files that have been modified in the working directory but not yet staged for commit.
  3. Staged Files:

    • Files that have been added to the staging area (using git add) and are ready to be committed. 
       git commit -m "Your commit message"
      

  4. Branch Information:

    • The current branch you are on.
    • Whether your branch is up-to-date, ahead, or behind the remote branch (if you have one).
  5. Other Information:

    • If there are files in conflict due to a merge.
    • If there are unmerged paths.
    • Information about ignored files (files that are excluded using .gitignore).


Example Output of git status:

Here is what the output might look like after running git status:

On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   file1.txt
    modified:   file2.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    newfile.txt

no changes added to commit (use "git add" and/or "git commit -a")

Key Parts of the Output:

  • Branch Info:
    "On branch main" – shows you're currently on the main branch.

  • Changes not staged for commit:
    Lists files that have been modified but are not yet staged (e.g., file1.txt, file2.txt).

  • Untracked files:
    Lists files that are not tracked by Git (e.g., newfile.txt), and Git suggests adding them if you want to track them.


The git status command is very useful for seeing what you’ve changed and making sure everything is set before committing to a Git repository.