MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Initializing a Repository (git init and .git Directory Anatomy)0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
2.1Initializing a Repository (git init and .git Directory Anatomy)2.2Tracking Changes: git status and Staging with git add2.3Recording Snapshots: git commit and Semantic Commit Messages
HomeTutorialsGit & GitHub BasicsInitializing a Repository (git init and .git Directory Anatomy)
Tracking Changes: git status and Staging with git add

Initializing a Repository (git init and .git Directory Anatomy)

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Every Git project begins with repository initialization. Understanding what actually happens when you initialize a repository demystifies Git's internals and gives you total confidence when diagnosing repository issues.


1. Initializing a Repository with git init

To transform an existing project folder into a Git repository, navigate to the folder in your terminal and execute:

1# Navigate to your project directory
2cd my-web-app
3 
4# Initialize the Git repository
5git init

Terminal Output:

1Initialized empty Git repository in D:/projects/my-web-app/.git/
Note
[!NOTE] Running git init in a directory that already has a .git folder will not overwrite your existing commits or history. It simply re-initializes configuration or updates templates safely.

2. Deep Dive: Anatomy of the .git Directory

When you run git init, Git creates a hidden directory named .git. This hidden folder contains the entire database, configuration, and state of your repository.

Let's inspect what lies inside .git:

1.git/
2├── HEAD # Text file pointing to currently checked-out branch (e.g., ref: refs/heads/main)
3├── config # Project-specific configuration options (--local)
4├── description # Used primarily by GitWeb (default description text)
5├── hooks/ # Client-side and server-side script hooks (pre-commit, pre-push, etc.)
6├── info/
7│ └── exclude # Local exclusion file (similar to .gitignore, but not shared with others)
8├── objects/ # Object Database: stores all blobs (files), trees (directories), and commits
9│ ├── info/
10│ └── pack/ # Compressed packfiles for network and disk efficiency
11└── refs/ # References pointers
12 ├── heads/ # Pointers to local branches (e.g., main, feature-auth)
13 └── tags/ # Pointers to release tags (e.g., v1.0.0)

The 4 Key Components You Must Know:

  1. 1
    HEAD:
  • A single-line text file containing a reference pointer: ref: refs/heads/main.
  • It tells Git which branch and which commit your working directory currently reflects.
  1. 1
    config:
  • Stores repository-level preferences, remote repository URLs (origin), and branch tracking configurations.
  1. 1
    objects/:
  • The heart of Git's content-addressable storage. Files are compressed with zlib and stored by their 40-character SHA hash.
  1. 1
    refs/heads/:
  • Contains small files named after your branches. Each file contains nothing more than a 40-character commit hash.

3. Creating a Repo with a Custom Initial Branch

Modern development best practices specify main as the default branch rather than master:

1# Initialize repository with initial branch explicitly named 'main'
2git init -b main

4. How to Delete a Git Repository

What if you initialized Git in the wrong folder (e.g., accidentally inside your entire Desktop or Home directory)?

  • To remove Git version control, you do not need to uninstall Git.
  • Simply delete the hidden .git folder! Your project source files will remain completely untouched, but all version control history will be deleted.
1# On Linux / macOS:
2rm -rf .git
3 
4# On Windows PowerShell:
5Remove-Item -Recurse -Force .git

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What command initializes a brand new Git repository in the current working directory?
Question 2
What is the name of the hidden directory created by git init that stores all version control history?
Question 3
What is the role of the HEAD file inside the .git directory?
Question 4
How can you completely remove Git tracking from a folder while keeping all your actual project code files intact?
Question 5
What is stored inside the .git/objects/ folder?
Next Lesson

Tracking Changes: git status and Staging with git add

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Installing Git and Initial Configuration (git config user.name / email)Tracking Changes: git status and Staging with git add

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext