In Git, files do not automatically jump from your text editor into the permanent commit history. You must explicitly inspect your changes using git status and stage them using git add. This deliberate workflow gives you total control over what enters your project history.
git statusThe git status command displays the exact state of your working directory and staging area relative to your last commit:
When you run git status, Git categorizes files into three distinct sections:
git add, ready for the next commit.-s or --short)Output flags:
?? : Untracked file M (space then M in red) : Modified in working tree, not stagedM (green M then space) : Staged and ready to commitMM : Staged, but modified again in working directory after staging!git addThe git add command copies changes from the Working Directory into the Staging Area (The Index):
git add Variations:git add . without checking git status first is dangerous! You risk accidentally staging sensitive environment files (.env), database passwords, or bloated dependencies (node_modules). Always review git status first.git add -p)What if you made 20 lines of changes in app.js, but 10 lines belong to a bug fix and 10 lines belong to an unfinished new feature? You can stage individual "hunks" (chunks) interactively using the patch flag:
Git will display each modified chunk and prompt:
y : stage this hunkn : do not stage this hunks : split this hunk into smaller piecesq : quit interactive staginggit restore --staged)If you accidentally staged a file that shouldn't be in the commit:
git status?git add . do?git status -s (short status), what does a green M on the left followed by a space mean?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.