Lesson 6 +10 XP

Adding New Files

When you create a new file in a Git repository, Git does not track it until you tell it to.

The add command

Use git add to start tracking a file:

Code

bash
git add index.html

To add a whole folder:

Code

bash
git add images/

To add everything at once:

Code

bash
git add .

Check what Git sees

Code

bash
git status

Before adding, new files show up as untracked. After git add, they move to the staging area and show as "new file" changes ready to commit.

Tracked vs untracked

  • Untracked: Git never saw this file before.
  • Tracked: Git watches this file and knows its history.
  • Staged: the file is ready to be committed.

Example

Code

bash
git status
git add index.html
git status

The first git status shows your file as untracked. After git add, the same file appears as a staged change.

TL;DR

  • git add file starts tracking a file.
  • git add . adds all changes.
  • Untracked files become tracked once you add them.
  • Added files sit in the staging area, ready to commit.