Lesson

Git New Files

10 min reading
Free Course

Git New Files: Understanding Tracked and Untracked Files

Every file inside a Git repository is either tracked or untracked. Tracked files belong to your last committed snapshot or are staged for the next commit, while new files you just created start out untracked until you stage them.

Creating Starter Project Files

Create two small files in your starter-site folder—an index.html page and a styles.css stylesheet—so you can watch how Git classifies brand-new files:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Starter Site</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header>
    <h2>Starter Site</h2>
    <p>First tracked HTML page in our repository.</p>
  </header>
</body>
</html>
body {
  font-family: system-ui, sans-serif;
  margin: 2rem;
  color: #1e293b;
}

Checking File States with git status

After saving index.html and styles.css, run git status in your terminal:

git status

Git lists both files under Untracked files and reminds you to run git add <file> to include them in what will be committed. Git intentionally refuses to auto-include new files so temporary logs, local .env secrets, or compiled binaries do not slip into version history by accident.

Moving a File from Untracked to Tracked

To start tracking index.html and styles.css, stage them with git add and inspect git status again:

git add index.html styles.css
git status

Both files now move to Changes to be committed as new file. Once you commit them, Git tracks every future edit or deletion to those two files automatically.

Common Mistakes with New Files

Forgetting to run git add on a newly created file and then running git commit -a is a classic trap. The -a flag only commits modifications to already-tracked files and silently skips untracked files.

If you accidentally create a file that should never be tracked, delete it or add its filename pattern to .gitignore before running git add ..

Frequently Asked Questions

What are the four main file states in Git?

A file in a Git repository is either untracked, unmodified (matches the last commit), modified (edited since the last commit), or staged (marked for the next commit).

How do I untrack a file that I staged by mistake?

Before committing, run git restore --staged <filename> to move the file back to untracked without deleting it from your disk.

Why does git status not show an empty folder?

Git tracks file contents rather than empty directories. If you need an empty folder like assets/ in your repository, add a small placeholder file such as .gitkeep inside it.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum