Bird
Raised Fist0
Gitdevops~10 mins

Untracked vs tracked files in Git - Visual Side-by-Side Comparison

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Untracked vs tracked files
Create new file
File is untracked
Run git add
File becomes tracked (staged)
Run git commit
File is tracked (committed)
This flow shows how a new file starts as untracked, then becomes tracked after adding and committing.
Execution Sample
Git
echo "Hello" > file.txt
git status
git add file.txt
git status
git commit -m "Add file.txt"
git status
This sequence creates a file, checks status (untracked), adds it, commits it, and checks status again.
Process Table
StepCommandGit Status Output SummaryFile State
1echo "Hello" > file.txtNo git output; file created in folderfile.txt created, untracked
2git statusShows: untracked files: file.txtfile.txt is untracked
3git add file.txtNo output; file stagedfile.txt staged (tracked)
4git statusShows: changes to be committed: new file: file.txtfile.txt staged (tracked)
5git commit -m "Add file.txt"[master (root-commit) abc1234] Add file.txt 1 file changed, 1 insertion(+) create mode 100644 file.txtfile.txt committed (tracked)
6git statusShows: nothing to commit, working tree cleanfile.txt tracked and committed
💡 After commit, file is tracked and no changes pending.
Status Tracker
File StateStartAfter Step 2After Step 3After Step 5Final
file.txtDoes not existUntrackedStaged (tracked)Committed (tracked)Committed (tracked)
Key Moments - 3 Insights
Why does the file show as untracked before running git add?
Because the file is new and git does not track it until you explicitly add it, as shown in execution_table step 2.
What changes the file from untracked to tracked?
Running git add stages the file, changing its state to tracked, as seen in execution_table step 3.
Why does git status show nothing to commit after the commit?
Because the file is now committed and there are no new changes, as shown in execution_table step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the file state after running 'git add file.txt'?
AUntracked
BCommitted
CStaged (tracked)
DDeleted
💡 Hint
Check the 'File State' column at step 3 in the execution_table.
At which step does the file become committed?
AStep 5
BStep 2
CStep 3
DStep 6
💡 Hint
Look for the commit command and output in the execution_table.
If you create a new file but never run git add, what will git status show?
AFile is committed
BFile is untracked
CFile is staged
DFile is deleted
💡 Hint
Refer to the file state at step 2 in the execution_table.
Concept Snapshot
Untracked files are new files git does not track yet.
Run 'git add <file>' to stage and track them.
Run 'git commit' to save changes permanently.
'git status' shows file states: untracked, staged, committed.
Files stay untracked until added.
Full Transcript
When you create a new file in a git folder, it starts as untracked. This means git knows the file exists but does not track changes to it yet. Running 'git status' shows untracked files. To track the file, you run 'git add <filename>', which stages the file. Staged files are tracked and ready to be committed. After running 'git commit', the file is saved in the git history and is fully tracked. Running 'git status' after commit shows a clean working tree with no changes. This flow helps you understand how files move from untracked to tracked in git.

Practice

(1/5)
1. What does it mean when a file is untracked in Git?
easy
A. The file is already included in the last commit.
B. Git does not know about the file yet and it is not included in commits.
C. The file is ignored by Git due to .gitignore rules.
D. The file is staged and ready to be committed.

Solution

  1. Step 1: Understand the meaning of untracked files

    Untracked files are those that Git has not seen before and are not part of any commit.
  2. Step 2: Compare with tracked files

    Tracked files are known to Git and included in commits, unlike untracked files.
  3. Final Answer:

    Git does not know about the file yet and it is not included in commits. -> Option B
  4. Quick Check:

    Untracked = Not known to Git [OK]
Hint: Untracked means Git hasn't seen the file yet [OK]
Common Mistakes:
  • Confusing untracked with ignored files
  • Thinking untracked files are staged
  • Assuming untracked files are committed
2. Which Git command is used to start tracking an untracked file?
easy
A. git commit
B. git status
C. git push
D. git add

Solution

  1. Step 1: Identify the command to track files

    The git add command tells Git to start tracking a file by adding it to the staging area.
  2. Step 2: Differentiate from other commands

    git commit saves changes, git push sends commits to remote, and git status shows file states.
  3. Final Answer:

    git add -> Option D
  4. Quick Check:

    Start tracking = git add [OK]
Hint: Use git add to track new files [OK]
Common Mistakes:
  • Using git commit before adding files
  • Confusing git push with tracking
  • Thinking git status tracks files
3. Given the following Git status output:
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    newfile.txt

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    modified: trackedfile.txt

Which files are currently tracked by Git?
medium
A. trackedfile.txt only
B. Both newfile.txt and trackedfile.txt
C. newfile.txt only
D. Neither file is tracked

Solution

  1. Step 1: Analyze the status output sections

    The "Untracked files" section lists files Git does not track yet, here newfile.txt. The "Changes to be committed" section lists tracked files staged for commit, here trackedfile.txt.
  2. Step 2: Determine tracked files

    Only trackedfile.txt is tracked because it is staged. newfile.txt is untracked.
  3. Final Answer:

    trackedfile.txt only -> Option A
  4. Quick Check:

    Tracked files = staged or committed files [OK]
Hint: Tracked files appear under 'Changes to be committed' [OK]
Common Mistakes:
  • Assuming untracked files are tracked
  • Confusing staged with untracked
  • Ignoring the status section labels
4. You ran git add newfile.txt but git status still shows newfile.txt as untracked. What is the most likely reason?
medium
A. The file is listed in .gitignore and ignored by Git.
B. You forgot to commit after adding the file.
C. You used the wrong filename in the add command.
D. Git does not track files with certain extensions.

Solution

  1. Step 1: Understand why git add might not track a file

    If a file is ignored by Git due to .gitignore rules, git add will not track it and it remains untracked.
  2. Step 2: Eliminate other reasons

    Committing is not required to track a file; wrong filename would cause an error; Git tracks all extensions unless ignored.
  3. Final Answer:

    The file is listed in .gitignore and ignored by Git. -> Option A
  4. Quick Check:

    Ignored files stay untracked despite git add [OK]
Hint: Check .gitignore if git add doesn't track file [OK]
Common Mistakes:
  • Thinking commit is needed to track
  • Ignoring .gitignore rules
  • Assuming Git restricts file types
5. You have a folder with files: file1.txt (tracked, modified), file2.txt (untracked), and file3.log (untracked). Your .gitignore contains *.log. You want to commit file2.txt but not the changes in file1.txt or file3.log. What is the correct sequence of commands?
hard
A. git add file3.log; git commit -m "Add file3"
B. git add .; git commit -m "Add all files"
C. git add file2.txt; git commit -m "Add file2"
D. git commit -a -m "Add file2 and file3"

Solution

  1. Step 1: Understand .gitignore effect

    The pattern *.log in .gitignore causes file3.log to be ignored and untracked, so it won't be added by git add ..
  2. Step 2: Choose commands to add only file2.txt

    Using git add file2.txt adds only that file without staging changes to tracked file1.txt. Then commit saves it. git add file3.log is ignored. git add . would add file2.txt AND stage changes to file1.txt. Using git commit -a only commits tracked files, so untracked file2.txt won't be included.
  3. Final Answer:

    git add file2.txt; git commit -m "Add file2" -> Option C
  4. Quick Check:

    Use git add on untracked file, ignore .log files [OK]
Hint: Add untracked files explicitly; .gitignore blocks others [OK]
Common Mistakes:
  • Using git commit -a to add untracked files
  • Adding ignored files by mistake
  • Using git add . which also stages changes to tracked files