Chapter 5: Git New Files
What is Git New Files?
This is actually one of the most confusing parts for absolute beginners, so I’m really glad you asked.
“Git new files” refers to how Git treats brand-new files you just created in your project folder — files that Git has never seen before.
Git calls these untracked files.
Until you explicitly tell Git “yes, please start watching this file”, Git completely ignores it. It won’t include it in commits, backups, history — nothing. That’s by design (safety + control).
Let me explain it like we’re building a small todo app together, step by step, with real terminal examples and what you’ll actually see.
1. The Three States a File Can Be In (Super Important Mental Model)
Git looks at every file in your working directory and puts it into one of these buckets:
| State | Meaning in Plain English | Color in git status | Included in next commit? | How to get there / change it |
|---|---|---|---|---|
| Untracked | New file Git has never seen or been told to care about | red | No | Create file → stays untracked until you git add |
| Staged (also called “Changes to be committed”) | You told Git “yes, include this in my next snapshot” (via git add) | green | Yes | git add file.txt |
| Tracked & Modified (but not staged) | File was already in a previous commit, you changed it, but haven’t git added yet | red (under “Changes not staged”) | No (until staged) | Edit tracked file → becomes modified unstaged |
New files always start as untracked.
2. Hands-on Example – Let’s Create “New Files” Right Now
Make a playground folder (or continue from previous lessons):
|
0 1 2 3 4 5 6 7 8 |
mkdir git-new-files-demo cd git-new-files-demo git init |
Now create three brand-new files (use VS Code, Notepad, or terminal):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
# File 1: Important one we WANT Git to track echo "# Todo App" > README.md # File 2: Secret file we DON'T want in Git (passwords, logs, etc.) echo "mysecretpassword123" > secret.txt # File 3: Temporary file (like a scratch note) echo "testing 1 2 3" > temp.log |
Run the magic command that shows everything:
|
0 1 2 3 4 5 6 |
git status |
You will see exactly this (or very similar):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) README.md secret.txt temp.log nothing added to commit but untracked files present (use "git add" to track) |
→ All three files are red = untracked = Git pretends they don’t exist for version control purposes.
3. How to Make a “New File” Become Tracked (The git add Step)
This is the key moment.
|
0 1 2 3 4 5 6 7 |
# Tell Git: "Start tracking this important file from now on" git add README.md |
Now check again:
|
0 1 2 3 4 5 6 |
git status |
Now you see:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: README.md Untracked files: (use "git add <file>..." to include in what will be committed) secret.txt temp.log |
→ README.md moved to green = staged = “new file” that will be part of the next commit → The other two are still untracked (ignored by Git for now)
Commit it:
|
0 1 2 3 4 5 6 |
git commit -m "Add README as first tracked file" |
Now run git status again:
|
0 1 2 3 4 5 6 7 |
On branch main nothing to commit, working tree clean |
→ README.md is now tracked forever (unless deleted). Future changes to it will show as modified (red) until you git add again.
But secret.txt and temp.log? Still untracked — Git will never commit them unless you explicitly git add them.
4. Quick Ways People Add New Files (Common Commands)
| What you want | Command | What it actually does |
|---|---|---|
| Add one specific new file | git add index.html | Tracks & stages only that file |
| Add all new + changed files in this folder | git add . | Most common! Adds everything (new + modified) in current directory & subfolders |
| Add every untracked/modified file everywhere | git add -A or git add –all | Adds literally everything (even files in parent folders if you’re deep in subfolder) |
| Only add already-tracked files (ignore new ones) | git add -u | Useful when you created junk files and don’t want to accidentally add them |
Pro tip most beginners miss: git commit -a -m “message” → Commits only already-tracked modified/deleted files — does NOT add new/untracked files. Many people get confused here → “Why didn’t my new file commit?!”
5. What Happens If You Accidentally Add Something Bad?
Example: Oops, added secret.txt by mistake with git add .
Undo staging (but keep the file on disk):
|
0 1 2 3 4 5 6 7 |
git restore --staged secret.txt # or older syntax: git reset secret.txt |
Now it’s back to untracked.
To permanently stop Git from suggesting it every time:
Create a file called .gitignore and add:
|
0 1 2 3 4 5 6 7 8 9 |
secret.txt *.log node_modules/ .env |
|
0 1 2 3 4 5 6 7 |
git add .gitignore git commit -m "Add .gitignore to ignore secrets and temp files" |
Now git status will never show those files again (super clean!).
Summary Table – New Files Lifecycle
- You create style.css → Untracked (red in status)
- You run git add style.css → Staged (green) + now tracked forever
- You run git commit → File is in history (snapshot taken)
- Later you edit style.css → Modified (red under “Changes not staged”)
- git add style.css again → Staged the new changes
- git commit → New version saved
That’s the full circle!
Got it? New files = untracked until git add → that’s the “Git new files” moment.
Want to practice deeper?
- Shall we do a full example with .gitignore?
- See what happens with folders of new files?
- Or move to “how to remove a file from tracking”?
Just tell me — we’re building this step by step. You’re doing fantastic! 🚀
