Git New Files provides essential version control capabilities for managing codebase changes cleanly, predictably, and efficiently.
A new file is a file that you have created or copied into your project folder, but haven't told Git to watch.
Here are the key things to know:
ls - List files in the foldergit status - Check which files are trackedYour new Git repository is empty.
Let's add a file using your favorite text editor, and save it in your project folder.
If you need help creating a file, see our HTML Editors page.
For this example, we'll use a simple HTML file:
Example: Simple HTML File
<!DOCTYPE html>
<html><head><title>Hello World!</title>
</head><body><h1>Hello world!</h1><p>This is
the first file in my new Git Repo.</p>
</body></html>
Save this as index.html in your project folder.
To see which files are in your project folder, use the ls command:
Example
ls
index.html
ls lists all files in the current folder.
You should see index.html in the output.
git statusNow check if Git is tracking your new file:
Example
git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
index.html
nothing added to commit but untracked files present (use "git add" to track)
Git sees index.html, but it is untracked (not yet added to the repository).
An untracked file is any file in your project folder that Git is not yet tracking.
These are files you've created or copied into the folder, but haven't told Git to watch.
A tracked file is a file that Git is watching for changes.
To make a file tracked, you need to add it to the staging area (covered in the next chapter).
ls: Make sure you saved it in the correct folder.pwd to check your current directory.git status: Make sure you are in the correct folder and that you saved the file.Execute the following terminal commands to work with this concept in your workspace:
# Check repository status
git status
# View formatted log
git log --oneline -n 5
Fix CORS bug rather than Fixed CORS bug).git diff to review unstaged modifications before adding files to the index.git switch -c <branch-name> to preserve edits.git restore --staged <filename> to remove the file from the index without altering your local workspace copy.Open your terminal in a test project directory, execute git status, and verify your current working tree state. Practice running git log --oneline to review commit history.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With