0
0
Gitdevops~5 mins

Untracked vs tracked files in Git - CLI Comparison

Choose your learning style9 modes available
Introduction
When you work with Git, files in your project can be either tracked or untracked. Tracked files are those Git knows about and monitors for changes. Untracked files are new files Git has not started tracking yet. Understanding this helps you control what changes get saved in your project history.
When you create a new file and want to add it to your project history.
When you want to see which files are new and not yet added to Git.
When you want to ignore certain files so Git does not track them.
When you want to check if your changes are ready to be saved.
When you want to clean up files that are not part of your project.
Commands
This command shows the current state of your project, listing tracked files with changes and untracked files that Git does not know yet.
Terminal
git status
Expected OutputExpected
On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) newfile.txt nothing added to commit but untracked files present (use "git add" to track)
This command tells Git to start tracking the new file by adding it to the staging area, preparing it to be saved in the next commit.
Terminal
git add newfile.txt
Expected OutputExpected
No output (command runs silently)
Run again to see that the file is now tracked and staged for commit.
Terminal
git status
Expected OutputExpected
On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: newfile.txt
This command saves the staged changes (including the new tracked file) into the project history with a message describing the change.
Terminal
git commit -m "Add newfile.txt"
Expected OutputExpected
[main (root-commit) abcdef1] Add newfile.txt 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 newfile.txt
-m - Add a commit message inline
Check the status again to confirm there are no untracked or unstaged changes left.
Terminal
git status
Expected OutputExpected
On branch main nothing to commit, working tree clean
Key Concept

If you remember nothing else from this pattern, remember: untracked files are new files Git does not monitor until you add them, and tracked files are those Git watches for changes.

Common Mistakes
Trying to commit a new file without adding it first
Git will not include untracked files in commits unless they are added to the staging area.
Use 'git add filename' to start tracking the file before committing.
Ignoring untracked files that should be part of the project
Important new files will not be saved in the project history and can be lost.
Regularly check 'git status' and add new files you want to keep.
Adding files that should be ignored (like logs or temp files)
This clutters the project history with unnecessary files.
Use a .gitignore file to tell Git which files to ignore.
Summary
Use 'git status' to see which files are tracked and untracked.
Add new files with 'git add filename' to start tracking them.
Commit tracked changes with 'git commit -m "message"' to save them.