← Back to Git Course | Chapter 1: Introduction & Setup | Lesson 5 of 7

Git First Repository

A repository is like a school project folder that has a secret notebook tucked inside, where Git writes down every change ever made. Everything looks normal on top, but the hidden notebook keeps the history.
Syntax
bash
mkdir project_folder
cd project_folder
git init

What is a Git Repository?

A Git repository is just a normal folder plus one hidden subfolder, .git, where Git actually stores the entire tracking database -- every commit, branch pointer, and piece of history lives inside that one directory, invisible during everyday work.

Example: What is a Git Repository?

bash
git init
ls -la

Creating a Project Folder

Before you can track anything, you need a clean folder to work in: mkdir my-project creates it and cd my-project moves your terminal inside it, giving Git an empty starting point with no unrelated files to confuse it.

Example: Creating a Project Folder

bash
mkdir my-project
cd my-project

Initializing Git in the Folder

Running git init inside that folder is the one command that actually turns a plain directory into a Git repository -- it creates the hidden .git database and nothing else, so your existing files are completely untouched.

Example: Initializing Git in the Folder

bash
git init

Creating Your First File

With tracking active, create something for Git to actually track -- a README.md explaining the project, or a simple HTML page -- since an empty repository has nothing meaningful to commit yet.

Example: Creating Your First File

bash
echo "# My Project" > README.md

Verifying the Hidden .git Folder

Running ls -la (note the extra -a for all, which reveals hidden files) lets you confirm the .git folder really exists; if it's missing, git init either failed or was run in the wrong directory.

Example: Verifying the Hidden .git Folder

bash
ls -la
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Running git init in the wrong folder, such as your home directory, so Git tries to track everything inside it.
  2. Running git init again inside a folder that is already a repository or inside another repository, creating a nested .git.
  3. Deleting or editing the hidden .git folder, which destroys the repository's entire history.
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.