TExcelTAD
Home › Git › Git New Files

Git New Files

A brand-new file in a repository is untracked: Git sees it in the folder but does not include it in snapshots until you say so. This lesson shows how Git classifies files and how git status reports them.

Untracked files

Let's create a small website project with two files:

bash · try it yourself
mkdir website && cd website
git init -q
cat > index.html <<'EOF'
<!DOCTYPE html>
<html>
  <body><h1>Hello, Git!</h1></body>
</html>
EOF
printf 'body { font-family: sans-serif; }\n' > style.css
ls
git status
index.html
style.css
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	index.html
	style.css

nothing added to commit but untracked files present (use "git add" to track)

Git lists both files under Untracked files and even suggests the next command. Nothing has been committed, so the branch has "No commits yet".

The life cycle of a file

Each file in your folder is in one of these states:

State Meaning Shown by git status as
Untracked new, Git ignores it in commits Untracked files: / ??
Staged marked to go into the next commit Changes to be committed: / A, M in the first column
Unmodified tracked and identical to the last commit not shown
Modified tracked, changed since the last commit, not yet staged Changes not staged for commit: / M in the second column

Files move between these states with git add (untracked or modified → staged) and git commit (staged → unmodified). Editing a committed file makes it modified again.

Short status

The long format is friendly, but on a busy project git status -s (short) is easier to scan. Each line has two status columns: the left column is the staging area, the right column is the working folder.

bash · try it yourself
mkdir website && cd website
git init -q
echo "<h1>Home</h1>" > index.html
echo "body {}" > style.css
git add index.html
git commit -q -m "Add home page"
echo "<p>Welcome</p>" >> index.html
echo "About us" > about.html
git status -s
echo "---"
git add index.html
git status -s
 M index.html
?? about.html
?? style.css
---
M  index.html
?? about.html
?? style.css

Read the short codes like this:

Code Meaning
?? untracked
A added (new file staged)
M modified, not staged
M modified and staged
MM staged, then modified again
D / D deleted (unstaged / staged)

Empty folders are invisible

Git tracks files, not folders. A folder appears in a commit only when it contains at least one tracked file. A common convention is an empty placeholder file named .gitkeep:

bash · try it yourself
mkdir app && cd app
git init -q
mkdir logs images
git status -s
echo "(nothing listed: both folders are empty)"
touch images/.gitkeep
git status -s
git status -s -uall
(nothing listed: both folders are empty)
?? images/
?? images/.gitkeep

By default git status collapses an untracked folder into one line (images/); -uall lists every untracked file inside it.

Tip: Files you never want to track (build output, secrets, editor settings) belong in a .gitignore file, covered in the .gitignore lesson.

Test yourself

In git status -s, what does ?? mean?

  1. The file has a conflict
  2. The file is untracked
  3. The file is deleted
  4. The file is staged

What does the code M (space, then M) mean in short status?

  1. Modified and staged
  2. Modified in the working folder but not staged
  3. Moved
  4. Merged

You create an empty folder logs/. What does Git do with it?

  1. Commits it as an empty folder
  2. Ignores it until it contains a file
  3. Reports an error
  4. Adds it to .gitignore