Course contentsShow
← Software Engineering
Lesson 45 of 1,9332. Version Control with GitFree lesson

Creating Your First Repository

Initializing a Git repository with 'git init' and understanding the .git directory structure.

Creating Your First Repository

You'll learn how to initialize a Git repository and what happens behind the scenes when you do.

Now that you have Git installed, it's time to create your first repository—a special folder where Git will track all changes to your files.

Starting Your Repository with git init

To turn any folder into a Git repository, navigate to that folder in your terminal and run:

git init

That's it! Git immediately creates a hidden folder called .git inside your project directory. This single command transforms an ordinary folder into a version-controlled workspace.

Analogy: Think of git init like buying a filing cabinet for your office. The cabinet itself (the .git folder) will store all your organized records, but your desk (your working directory) stays clear for daily work.

What's Inside the .git Directory?

The .git folder is Git's "brain"—it contains everything Git needs to track your project's history:

  • objects/: Stores all versions of your files
  • refs/: Keeps track of branches and tags
  • HEAD: Points to your current working branch
  • config: Repository-specific settings
  • hooks/: Scripts that run automatically at certain events

You'll rarely need to touch these files directly—Git manages them for you. The important thing is understanding that this hidden folder is what makes version control possible.

Warning: Never delete the .git folder unless you want to lose all your project history!

Your Working Directory vs The Repository

After running git init, you have two spaces: your working directory (where you edit files normally) and the repository (the .git folder tracking changes). They exist side-by-side in the same location.

Key Takeaway: git init creates a .git directory that stores all version control data, transforming any folder into a Git repository without changing your actual project files.