← Back to Git Course | Chapter 2: Basic Commands | Lesson 2 of 18

Git New Files

New files you create aren't automatically part of a Git repository -- they start out as untracked, and git status and git add are how you tell Git to start following and staging them.

Untracked Files and git status

A newly created file that Git has never been told about is called untracked -- running git status lists it separately from modified tracked files, under its own 'Untracked files' heading, so you can see exactly what exists on disk but isn't yet part of the repository's history.

Example: Untracked Files and git status

bash
git status

Adding a Single New File

Running git add followed by a file path moves that single file from the untracked or modified state into the staging area, marking it to be included in the next commit without affecting any other files that are currently untracked or modified.

Example: Adding a Single New File

bash
git add index.html

Adding Multiple New Files

Multiple file paths can be listed after git add in one command, separated by spaces, or matched with a shell wildcard like *.css, which stages every file matching the pattern at once instead of requiring a separate git add command for each file.

Example: Adding Multiple New Files

bash
git add file1.txt file2.txt
git add *.css

Adding All New Files with git add .

git add . stages every new and modified file found in the current directory and all of its subdirectories, while git add -A goes further and stages the entire repository including deletions, regardless of which directory the command is run from.

Example: Adding All New Files with git add .

bash
git add .
git add -A

Checking What Will Be Committed

Before committing, git status summarizes which files are staged and which are still untracked or modified, and git diff --cached shows the exact line-by-line content that has been staged, letting you confirm precisely what will be recorded in the next commit.

Example: Checking What Will Be Committed

bash
git status
git diff --cached

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.