~/hackweb.dev
Creating a Repository
Quiz
...

Creating a Repository

beginner · updated Tue Sep 08 2026Contribute

Initialize a new Git repository and understand what .git/ contains.

Creating a Repository

To start tracking a project with Git, you need to create a repository. This is a one-time setup per project.

Initializing a Repository

Navigate to your project folder and run:

git init
# Initialized empty Git repository in /path/to/project/.git/

What Happens Inside .git/

Git creates a .git/ directory with everything it needs:

ls -la .git/
# HEAD
# config
# description
# hooks/
# info/
# objects/
# refs/

This folder contains your entire history once you start committing.

Working Directory vs Repository

  • Working directory: Your project files (the ones you see and edit)
  • Repository: The .git/ folder where Git stores all tracking data

Alternative: git clone

Instead of starting fresh, you can copy an existing repository:

git clone https://github.com/user/project.git

This creates a full copy with all history and files.

Best Practices

  • Initialize Git at the start of a project
  • Keep your .git/ folder safe (don’t delete it)
  • Use git clone for existing projects
  • Add a .gitignore file early to exclude files

Common Mistakes

  • Running git init multiple times in the same project
  • Deleting the .git/ folder (destroys all history)
  • Forgetting to initialize before making commits
  • Not adding a .gitignore for sensitive files