Initializing a Repository
A repository — often called a "repo" — is simply a folder that Git is tracking. When you initialize a repository, Git starts watching for changes and becomes ready to record your project's history. This is a one-time action for each project.
Creating Your First Repository
Navigate to your project folder in the terminal, then run git init:
That's it. Your folder is now a Git repository. You can run git init in an empty folder before adding files, or in an existing project folder that already has code.
What Git Creates
When you initialize a repository, Git creates a hidden folder called .git inside your project directory. This folder contains everything Git needs to track your project:
- The complete history of all changes
- Information about branches
- Configuration specific to this repository
You won't see .git in normal file listings because it's hidden. On macOS or Linux, you can reveal it with ls -la. The important thing is: don't manually edit or delete the .git folder. If you do, you'll lose your entire project history.
One Project, One Init
You only run git init once per project. Running it again in the same folder won't hurt anything — Git will just tell you the repository already exists — but there's no reason to do it.
If you accidentally initialize Git in the wrong folder, simply delete the .git folder to undo it:
This removes all Git tracking from that folder. Be careful — this also deletes all commit history if you had any.
What Happens Next
After initializing, Git is watching but hasn't recorded anything yet. Your files exist in the folder, but Git considers them "untracked" — it sees them but isn't saving their history. The next step is to tell Git which files to track and make your first commit.
Think of git init as setting up a camera. The camera is ready, but you haven't pressed record yet.