Initializing a Repository
The git init command creates a new Git repository.
Creating a New Repository
When you run git init, Git creates a hidden .git folder that stores all version control information.
What Happens During Init
When you initialize a repository:
- Git creates a
.gitdirectory - Sets up the default branch (usually
main) - Creates initial configuration files
- Prepares the staging area
The .git Directory
The .git folder contains:
.git/
├── HEAD # Points to current branch
├── config # Repository settings
├── objects/ # Stored commits and files
├── refs/ # Branch and tag pointers
└── hooks/ # Automation scripts
Starting Fresh vs Cloning
| Scenario | Command |
|---|---|
| New project | git init |
| Existing project | git clone <url> |
Common Init Patterns
Initialize and Add Remote
git init
git remote add origin https://github.com/user/repo.git
git add .
git commit -m "Initial commit"
git push -u origin main
Initialize with Branch Name
git init -b main
Exercise: Initialize a Repository
The terminal below already has an initialized repository. Run git status to confirm it's working:

