Course contentsShow
← Computer Science
Lesson 2170 of 2,87249. Version Control with GitFree lesson

Creating a Git Repository

Initialize a new Git repository with 'git init' and understand the .git directory structure.

Creating a Git Repository

What you'll learn: How to initialize a new Git repository and what happens under the hood when you do.

The Core Idea

Creating a Git repository transforms an ordinary folder into a version-controlled workspace. You do this with a single command: git init. Think of it like converting a regular notebook into a laboratory logbook—suddenly every change, note, and experiment can be tracked, compared, and revisited.

When you run git init in a directory, Git creates a hidden .git subdirectory that contains all the machinery needed to track your project's history.

How to Initialize a Repository

Navigate to your project folder and run:

git init

You'll see a message like "Initialized empty Git repository in /path/to/project/.git/". Your folder is now a Git repository—nothing about your existing files has changed, but Git is now ready to track them.

Understanding the .git Directory

The .git directory is Git's "control center." It contains several important subdirectories and files:

  • objects/: Stores all your file content and commit history as compressed objects
  • refs/: Holds references to commits (branches and tags)
  • HEAD: Points to your current branch
  • config: Repository-specific configuration settings
  • hooks/: Scripts that run automatically at certain Git events

You should never manually edit files inside .git—Git commands handle everything. Think of it as the engine of a car: it powers everything, but you interact through the steering wheel and pedals (Git commands), not by touching the pistons.

Key Takeaway: git init creates a .git directory that holds all version control metadata; this hidden folder is what makes a regular directory into a Git repository capable of tracking changes.