Git New Files
In this page:
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
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
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
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 .
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
git status
git diff --cached
Chapter Quiz — Complete all 18 topics to unlock
0/18 topics done
Complete these topics first:
- Git init Command
- Git New Files
- Git Staging Environment
- Git clone Command
- Git status Command
- Git help Command
- Git add Command
- Git commit Command
- Git tags Command
- Git stash Command
- Git log Command
- Git diff Command
- Git show Command
- Git rm Command
- Git mv Command
- Git restore Command
- Git clean Command
- Git ignore (.gitignore)