How to Add a File to Git Staging Area
In the previous blog, we learned how to convert a normal folder into a Git repository using git init. But until now, our project has been completely empty.
In this lesson, we’ll learn:
- How to create a file in a Git project
- How to check whether the file is tracked
- How to move the file into the staging area (also called the index area)
Step 1: Create a File
There are many ways to create a file in your project:
- Using a text editor like VS Code or Eclipse
- Or directly from the terminal
For this example, let’s create a file using the echo command:
echo "13.27.30" > first.txt
This command creates a new file called first.txt with the content 13.27.30.
If you run:
ls
You will see the file first.txt inside your project folder.
To view its content:
cat first.txt
Step 2: Check Staging Area Before Adding
Now let’s check the staging area. Run:
git ls-files
At this point, the command will not return anything. 👉 This means your staging area is empty.
Step 3: Add File to Staging Area
To move the file into the staging area, use:
git add first.txt
Now, if you check again:
git ls-files
You’ll see:
first.txt
🎉 This means the file is now in the staging area and ready to be committed.
Why Staging Area Matters
The staging area is like a waiting room before a commit:
- You decide which files go into the next snapshot of your project.
- You can prepare multiple files, review them, and then commit all at once.
🚀 Don’t Miss Out!
If you enjoyed this blog and want to learn Git step by step with me, then you’ll love what’s coming next.
👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.
👉 My YouTube Channel – More videos, more fun, and lots of learning!
👉 📺 Watch this topic in video form
Stay curious, keep coding, and let’s make learning fun together! 🎉