Git New Files
Adding Files to Git
Now that you've set up your Git repository, it's time to add some files. Currently, the repository is empty.
Create a New File
You can create a new file using your preferred text editor and save it in the project folder.
For example, let's create an HTML file named index.html:
<!DOCTYPE html> <html> <head> <title>My First Git File</title> </head> <body> <h1>Welcome to Git!</h1> <p>This is the initial file added to my Git repo.</p> </body> </html>
Save this file in your project directory.
Verify That the File Exists
Now, switch back to the terminal and check if the file is in your project folder:
Example:
ls
Output:
index.html
This confirms that the file is in the correct directory.
Check Git Status
Before adding the file, let's check its status in Git:
Example:
git status
Output:
On branch master No commits yet Untracked files: (use "git add <file>" to include in what will be committed) index.html No files have been committed yet, but untracked files exist (use "git add" to include them).
Understanding Git File States
Files in a Git repository can exist in two states:
- Untracked – Files that exist in the directory but are not being monitored by Git.
- Tracked – Files that have been added to the repository and are being tracked for changes.
Initially, all newly created files are untracked. To start tracking them, we need to add them to the staging area.
PreviousNext