MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Tracking Changes: git status and Staging with git add0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
2.1Initializing a Repository (git init and .git Directory Anatomy)2.2Tracking Changes: git status and Staging with git add2.3Recording Snapshots: git commit and Semantic Commit Messages
HomeTutorialsGit & GitHub BasicsTracking Changes: git status and Staging with git add
Recording Snapshots: git commit and Semantic Commit Messages

Tracking Changes: git status and Staging with git add

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

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.


1. Checking Status with git status

The git status command displays the exact state of your working directory and staging area relative to your last commit:

1git status

Understanding Status Outputs:

When you run git status, Git categorizes files into three distinct sections:

  1. 1
    Changes to be committed (Staged): Files added to the staging area with git add, ready for the next commit.
  2. 2
    Changes not staged for commit (Modified): Tracked files that have been edited on disk, but not yet staged.
  3. 3
    Untracked files: Brand new files that have never been committed or staged before.

Example Terminal Output:

1On branch main
2Changes to be committed:
3 (use "git restore --staged <file>..." to unstage)
4 new file: src/auth.js
5 
6Changes not staged for commit:
7 (use "git add <file>..." to update what will be committed)
8 (use "git restore <file>..." to discard changes in working directory)
9 modified: package.json
10 
11Untracked files:
12 (use "git add <file>..." to include in what will be committed)
13 notes.txt

Pro Tip: Compact Short Status (-s or --short)

1git status -s

Output flags:

  • ?? : Untracked file
  • M (space then M in red) : Modified in working tree, not staged
  • M (green M then space) : Staged and ready to commit
  • MM : Staged, but modified again in working directory after staging!

2. Staging Changes with git add

The git add command copies changes from the Working Directory into the Staging Area (The Index):

Common git add Variations:

1# 1. Stage a single specific file
2git add index.html
3 
4# 2. Stage multiple files explicitly
5git add app.js styles.css src/components/Header.jsx
6 
7# 3. Stage all files in a specific folder
8git add src/api/
9 
10# 4. Stage ALL modified, deleted, and untracked files across the entire repo
11git add .
12# Or equivalently:
13git add -A
Important Warning
[!WARNING] Blindly running 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.

3. Advanced Staging: Interactive Patch Staging (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:

1git add -p app.js

Git will display each modified chunk and prompt:

  • y : stage this hunk
  • n : do not stage this hunk
  • s : split this hunk into smaller pieces
  • q : quit interactive staging

4. Unstaging Files (git restore --staged)

If you accidentally staged a file that shouldn't be in the commit:

1# Unstage file (moves it back from Staging Area to Modified in Working Tree)
2git restore --staged unwanted_file.js
3 
4# Legacy syntax (older Git versions < 2.23):
5git reset HEAD unwanted_file.js

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What information is provided by running git status?
Question 2
What does the command git add . do?
Question 3
In git status -s (short status), what does a green M on the left followed by a space mean?
Question 4
Which command allows you to interactively review and stage individual hunks (parts) of a modified file?
Question 5
How do you safely remove a file from the staging area without losing the changes on your disk?
Next Lesson

Recording Snapshots: git commit and Semantic Commit Messages

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Initializing a Repository (git init and .git Directory Anatomy)Recording Snapshots: git commit and Semantic Commit Messages

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext