Bird
Raised Fist0
Gitdevops~10 mins

The .git directory structure - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - The .git directory structure
Initialize Git Repo
↓
.git directory created
↓
Create subdirectories: objects, refs, info
↓
Create files: HEAD, config, description
↓
Store commits, branches, tags inside .git
↓
Git commands read/write .git contents
This flow shows how the .git directory is created and structured when you initialize a Git repository, and how Git uses it to store all version control data.
Execution Sample
Git
git init
ls -la .git
cat .git/HEAD
Initialize a Git repo, list .git directory contents, and show the HEAD file content.
Process Table
StepCommandActionResult
1git initCreate .git directory and initial files.git directory with subfolders and files created
2ls -la .gitList contents of .git directoryShows folders: objects, refs, info and files: HEAD, config, description
3cat .git/HEADRead HEAD file contentref: refs/heads/main
4git statusGit reads .git to show repo statusShows working tree clean, branch main
💡 Initialization complete, .git directory fully set up and ready for version control
Status Tracker
VariableStartAfter git initAfter git status
.git directorynonecreated with subfolders and filesunchanged
HEAD filenonecontains 'ref: refs/heads/main'unchanged
refs/heads/mainnonenot yet created (no commits)unchanged
Key Moments - 3 Insights
Why does the .git directory have subfolders like objects and refs?
Because Git organizes data inside .git: 'objects' store all content snapshots, 'refs' store pointers to branches and tags. See execution_table step 1 and 2.
What does the HEAD file inside .git represent?
HEAD points to the current branch reference, usually 'refs/heads/main' initially. This is shown in execution_table step 3.
Why does git status read the .git directory?
Git reads .git to know the current branch and commit state to show status. This is shown in execution_table step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does the command 'cat .git/HEAD' output?
Aref: refs/heads/main
BList of files in .git
CCurrent commit hash
DError: file not found
💡 Hint
Check execution_table row 3 for the output of 'cat .git/HEAD'
At which step is the .git directory created?
AStep 2
BStep 3
CStep 1
DStep 4
💡 Hint
Look at execution_table step 1 where 'git init' creates the .git directory
If you run 'git status' before 'git init', what would happen?
AGit creates .git directory automatically
BGit errors because .git directory is missing
CGit shows working tree clean
DGit shows current branch as main
💡 Hint
Refer to variable_tracker showing .git directory is created only after 'git init'
Concept Snapshot
The .git directory is created by 'git init' and stores all Git data.
It contains subfolders like 'objects' (data storage), 'refs' (branches/tags), and files like 'HEAD' (current branch pointer).
Git commands read/write inside .git to track versions.
Understanding .git helps you know how Git manages your project history.
Full Transcript
When you run 'git init', Git creates a hidden folder called .git in your project. This folder holds everything Git needs to track your project versions. Inside .git, there are folders like 'objects' where Git stores snapshots of your files, and 'refs' where it keeps pointers to branches and tags. The HEAD file inside .git points to the current branch you are working on, usually 'refs/heads/main' at first. When you run commands like 'git status', Git reads the .git folder to understand your project's current state. Without the .git directory, Git cannot track changes or versions. This structure is the heart of Git's version control system.

Practice

(1/5)
1. What is the main purpose of the .git directory in a Git project?
easy
A. It stores all the data and history of the Git repository.
B. It contains the source code files of the project.
C. It holds temporary files created by the operating system.
D. It stores user configuration settings unrelated to Git.

Solution

  1. Step 1: Understand the role of .git directory

    The .git directory is created when you initialize a Git repository and it stores all Git-related data.
  2. Step 2: Differentiate from other directories

    Source code files are outside .git, and temporary or unrelated user files are not stored here.
  3. Final Answer:

    It stores all the data and history of the Git repository. -> Option A
  4. Quick Check:

    .git = Git data storage [OK]
Hint: Remember: .git holds Git's data, not project files [OK]
Common Mistakes:
  • Confusing .git with project source files
  • Thinking it stores temporary OS files
  • Assuming it holds unrelated user configs
2. Which of the following is a correct folder inside the .git directory?
easy
A. src
B. temp
C. bin
D. objects

Solution

  1. Step 1: Recall standard .git folders

    The .git directory contains folders like objects, refs, and hooks.
  2. Step 2: Identify the correct folder

    Among the options, only objects is a valid folder inside .git.
  3. Final Answer:

    objects -> Option D
  4. Quick Check:

    objects folder exists in .git [OK]
Hint: Look for Git-specific folders like objects [OK]
Common Mistakes:
  • Choosing project folders like src
  • Selecting unrelated folders like bin or temp
3. If you look inside the .git/refs/heads folder, what will you typically find?
medium
A. Configuration settings for Git hooks
B. Binary objects of the project files
C. Files representing branches in the repository
D. Temporary files created during commits

Solution

  1. Step 1: Understand refs/heads purpose

    The refs/heads folder stores files named after branches, each containing the commit hash of the branch tip.
  2. Step 2: Differentiate from other folders

    Binary objects are in objects, hooks configs are in hooks, and temporary files are not stored here.
  3. Final Answer:

    Files representing branches in the repository -> Option C
  4. Quick Check:

    refs/heads = branch pointers [OK]
Hint: Remember: refs/heads holds branch names [OK]
Common Mistakes:
  • Confusing branch refs with object storage
  • Thinking hooks configs are here
  • Assuming temporary files are stored here
4. You accidentally deleted the .git/HEAD file. What problem will this cause?
medium
A. Your project files will be deleted.
B. Git will lose track of the current branch or commit.
C. Git will stop tracking remote repositories.
D. Nothing will happen; Git recreates it automatically.

Solution

  1. Step 1: Understand the role of HEAD file

    The HEAD file points to the current branch or commit checked out in the working directory.
  2. Step 2: Consequence of deleting HEAD

    Without HEAD, Git cannot know which branch or commit is active, causing errors in commands.
  3. Final Answer:

    Git will lose track of the current branch or commit. -> Option B
  4. Quick Check:

    HEAD tracks current branch [OK]
Hint: HEAD file = current branch pointer; deleting it breaks Git [OK]
Common Mistakes:
  • Thinking project files get deleted
  • Assuming remote tracking is affected
  • Believing Git auto-recreates HEAD always
5. You want to manually inspect the commit history by reading files inside the .git directory. Which folder should you explore to find the actual commit objects?
hard
A. objects
B. hooks
C. refs
D. logs

Solution

  1. Step 1: Identify where commit data is stored

    The objects folder stores all Git objects including commits, trees, and blobs in compressed form.
  2. Step 2: Differentiate from other folders

    refs holds pointers to commits, hooks contains scripts, and logs track changes to refs.
  3. Final Answer:

    objects -> Option A
  4. Quick Check:

    Commit data = objects folder [OK]
Hint: Commit objects live in objects folder inside .git [OK]
Common Mistakes:
  • Confusing refs with actual commit data
  • Looking in hooks or logs for commits
  • Assuming commit data is in project files
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard