Lesson 11 of 60 – Git Status
18%

Git Status

The git status command is one of the most commonly used Git commands. It shows the current state of your working directory and staging area.

Note: Use git status frequently while working with Git. It helps you understand which files are modified, staged, untracked, or ready to be committed.

1. What is git status?

git status displays information about the current state of a Git repository.

git status

It helps you see what has changed since the last commit.

2. Why Use git status?

Git does not automatically show you every change in your project. The git status command helps you check what Git currently knows about your files.

It is useful before staging and committing changes.

3. Basic Syntax

The basic syntax is very simple:

git status

Run this command from inside a Git repository.

4. Running git status

Suppose you have a project called my-project. First enter the project:

cd my-project

Then run:

git status

5. Checking the Current Branch

The status output normally shows the branch you are currently working on.

For example, Git may display:

On branch main

This tells you that the current branch is main.

6. Clean Working Tree

If there are no changes to commit, Git may show a message similar to:

nothing to commit, working tree clean

This means there are no detected changes waiting to be committed.

7. Untracked Files

A file that Git is not currently tracking can appear under Untracked files.

Untracked files:
  index.html

You can stage the file using:

git add index.html

8. What is an Untracked File?

An untracked file is a new file in your working directory that has not yet been added to Git's staging area.

For example, after creating:

index.html

Git can show it as an untracked file.

9. Modified Files

When a tracked file is changed after the last commit, Git can show it as modified.

Changes not staged for commit:
  modified: index.html

This means the file has changes that have not yet been staged.

10. Staging a Modified File

After modifying a file, you can stage it with:

git add index.html

Run git status again to see the new state.

11. Changes to be Committed

After staging a file, Git can show it under:

Changes to be committed:

This means the changes are currently in the staging area and can be included in the next commit.

12. Example of Staged File

Changes to be committed:
  modified: index.html

The file has been staged and is ready for a commit.

13. Staging All Files

To stage all changes in the current directory, use:

git add .

Then check the result:

git status

14. Checking Status Before Commit

It is good practice to run git status before creating a commit.

git status
git commit -m "Update website"

This allows you to review which changes are staged.

15. Git Status After Commit

After committing all staged changes, run:

git status

If no additional changes exist, Git may report:

nothing to commit, working tree clean

16. Deleted Files

If a tracked file is deleted from the working directory, Git can show the deletion in the status output.

deleted: old-page.html

The deletion can then be staged before committing.

17. Staging a Deleted File

You can stage a deletion with:

git add old-page.html

Another command commonly used for staging file deletions and other changes is:

git add -A

18. Renamed Files

Git may recognize a file rename when changes are staged. The status output can show a renamed file.

renamed: old.html -> new.html

Git uses similarity between file contents when detecting renames.

19. Short Status Format

Git provides a compact status format using:

git status --short

This is useful when you want a shorter output.

20. Understanding Short Status

The short status format uses two columns to represent the state of files.

 M index.html
A  style.css
?? script.js

The two positions represent different types of changes in the index and working tree.

21. Status and the Staging Area

The status command helps you distinguish between changes that are only in the working directory and changes already staged in the index.

Working Directory
        ↓
    git add
        ↓
Staging Area
        ↓
   git commit

22. Status After Editing a File

git status

# edit index.html

git status

The second status check can show that index.html has been modified.

23. Status After Staging

git add index.html
git status

The modified file will now appear as a change staged for the next commit.

24. Status After Commit

git commit -m "Update index page"
git status

If no additional changes exist, the working tree can become clean.

25. Status in a New Repository

After creating a repository with:

git init

you can immediately check its state using:

git status

This is useful for confirming that you are working inside the correct repository.

26. Status and Branch Information

Git status can show the current branch at the beginning of its output. For example:

On branch main

This is useful when working with multiple branches.

27. Common Mistakes with git status

  • Running the command outside a Git repository.
  • Forgetting to stage modified files.
  • Assuming modified files are automatically committed.
  • Ignoring untracked files.
  • Not checking the branch before making changes.
  • Creating a commit without reviewing staged changes.

28. Useful Status Commands

git status
git status --short
git add .
git status
git commit -m "Update project"
git status

This simple sequence helps you understand the state of your project before and after a commit.

29. Complete Example

mkdir website
cd website

git init

touch index.html

git status

git add index.html

git status

git commit -m "Add index page"

git status

This example demonstrates how git status can be used throughout the basic Git workflow.

30. Summary of git status

The git status command gives you a clear view of the current state of your Git repository.

It can help you identify the current branch, untracked files, modified files, deleted files and changes that are already staged.

git status

Use it regularly before staging and committing your project changes.

📌 Key Points

  • git status shows the current state of a repository.
  • It can show the current branch.
  • It can show untracked files.
  • It can show modified files.
  • It can show deleted files.
  • It can show staged changes.
  • git status --short provides a compact status.
  • Use git add to stage changes.
  • Use git commit to record staged changes.
  • Use git status regularly during development.

🧠 Quick Quiz

Question: Which Git command shows the current state of the working directory and staging area?