Creating a Repository: git init
What is a Repository?
A repository (or repo) is a folder whose files are tracked by Git. When you initialize a repo, Git creates a hidden .git folder inside it to store the history.
Starting a New Repository
# Create and enter a project folder
mkdir my-project
cd my-projectInitialize Git tracking
git init
Output:
Initialized empty Git repository in /home/you/my-project/.git/
What Happens?
When you run git init, Git creates a hidden .git/ folder:
my-project/
├── .git/ ← Git's internal data (don't touch!)
│ ├── HEAD
│ ├── config
│ ├── objects/
│ └── refs/
└── (your files go here)
Checking the Status
After initializing, check the status:
git status
Output:
On branch main
No commits yet
nothing to commit
This tells you:
- You're on the main branch
- There are no commits yet
- There's nothing to commit (no files yet)
Important Rules
- One repo per project — Don't nest repos inside repos
- Don't init inside home — Always create a specific project folder first
- The .git folder is sacred — Never manually edit files inside
.git/
Summary
| Command | What It Does |
|---|---|
| <code>git init</code> | Start tracking a folder with Git |
| <code>git status</code> | Check current state of the repo |
| <code>ls -a</code> | See hidden files (including .git) |