This topic explains how to create new files in a Git repository, track them, stage them, and finally commit them. Adding new files is a fundamental Git workflow.
Git does not automatically track new files. You must explicitly add them to the staging area before committing.
// Create a new empty file
touch newfile.txt
// Check untracked and staged files
git status
// Add a specific file
git add newfile.txt
// Add all new and modified files
git add .
// Commit staged files with a message
git commit -m "Add newfile.txt"
// Display commit history
git log
// Remove a file before commit
git rm filename.txt
// Remove file from Git but keep locally
git rm --cached filename.txt
git status before committinggit log