Once you've initialized a Git repository, or after you've made some changes within an existing one, the most fundamental command you'll use is git status. Think of it as your repository's doctor, always ready to give you a health check. It tells you what Git knows about your project's current state – which files have been modified, which are new and untracked, and which are ready to be committed.
To see the status of your repository, simply navigate to your project's root directory in your terminal and type:
git statusThe output of git status is incredibly informative. Let's break down some common scenarios you might encounter.
Scenario 1: A clean repository. If you've committed all your changes, or if you haven't made any yet, git status will tell you that.
On branch main
nothing to commit, working tree cleanScenario 2: Modified files. If you've edited files that Git is already tracking, they will appear under the 'Changes not staged for commit' section.
On branch 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: README.md
no changes added to commit (use "git add" and/or "git commit -a")Scenario 3: New untracked files. When you create a new file that Git hasn't seen before, it will be listed under 'Untracked files'.
On branch main
Untracked files:
(use "git add <file>..." to include in what will be committed)
new_file.txt
nothing added to commit but untracked files present (use "git add" to track)Understanding git status is crucial. It's your constant companion, guiding you through the process of tracking changes and preparing them for your next commit. It helps you avoid accidentally committing unwanted changes or forgetting to include important ones.