How does 'git add' work?

QuestionsQuestions8 SkillsProDec, 24 2025
0121

Great question! Think of git add as the "Loading Dock" or "Shopping Cart" for your project.

When you run git add, you are moving changes from your Working Directory (where you edit files) to the Staging Area (the waiting room for the next save point).

Here is exactly what happens when you use it:

1. It Tracks the Untracked

Right now, your message.txt is "untracked." Git knows it exists, but it isn't "watching" it. Once you run git add message.txt, Git officially starts tracking that file.

2. It Prepares the "Snapshot"

Git doesn't automatically save every single keystroke. Instead, git add lets you hand-pick which specific changes are ready to be saved.

  • If you modified 10 files but only finished work on 2 of them, you only git add those 2.
  • The other 8 stay safely in your workspace without being part of the next "save point."

3. Common Ways to Use It:

  • Track a specific file: git add message.txt
  • Track everything in the folder: git add . (The period means "everything here")

Summary: The Workflow

  1. Modify/Create: You edit message.txt.
  2. Add (git add): You put the file in the "Staging Area" (Preparing the photo).
  3. Commit (git commit): You snap the photo and save it to history forever.

In your current lab, you are at Step 1. Once you run git add, you'll move to Step 2! You're doing great—give it a try in the next part of the tutorial!

0 Comments

no data
Be the first to share your comment!