
New Files in Git
🚀 How to Add New Files in Git
When you create new files in your Git repository, you need to stage, commit, and push them to GitHub. Here's how to do it step by step.
📌 Steps to Add New Files in Git
1️⃣ Create a New File
You can create a new file using a text editor or terminal:
touch newfile.txt
or
echo "Hello, Git!" > newfile.txt
2️⃣ Check the File Status
Use git status
to see untracked files:
git status
It will show:
Untracked files: (use "git add <file>..." to include in what will be committed)newfile.txt
3️⃣ Stage the New File
To add a single file:
git add newfile.txt
To add multiple files:
git add file1.txt file2.txt
To add all new and modified files:
git add .
4️⃣ Commit the File
After staging, commit the file with a message:
git commit -m "Added newfile.txt"
5️⃣ Push the File to GitHub
To push the changes to the main
branch:
git push origin main
For another branch (e.g., feature-branch
):
git push origin feature-branch
🔥 Example Workflow
git add hello.txtgit commit -m "Added hello.txt"git push origin main
🎯 Summary
✅ Create a file → touch filename
✅ Check status → git status
✅ Stage file → git add filename
✅ Commit file → git commit -m "message"
✅ Push to GitHub → git push origin branch-name