GIT - 4.4 Repository and git file

This lesson opens the hood on Git's internal storage. The starting point is a test project where one file coucou.html has already been committed. Listing with ls -al shows both the visible files and the hidden .git directory. What is interesting is that the visible folder we are currently in (the project folder) is the working directory of our repository, while the entire repository itself lives inside that hidden .git folder.

Stepping inside .git

We can navigate inside it just like any other folder:

cd .git

The shell prompt confirms we are now inside the .git directory. Looking around, we see Git's internal layout — many files and subfolders used and managed exclusively by Git itself (objects, refs, HEAD, config, hooks, etc.). Strong recommendation: stay outside .git unless you know exactly what you are doing. Touching files there by hand can corrupt the entire history. We jump back to the working directory:

cd ..

Proving the repository lives entirely in .git

To demonstrate that the repository is the .git folder, we completely delete it from the OS:

rm -rf .git

Right after the command, the shell prompt loses its branch indicator (no more master) because there is no repository anymore. Running ls shows that coucou.html is still there, but the .git folder is gone. The working files survive — only the version-control data is destroyed. Running any Git command such as git status now responds with an error stating that this is not a Git repository. This confirms a powerful mental model: your repository is the .git folder. Delete it, and Git forgets everything; back it up, and you back up the whole history.

Summary

This lesson explores the internal structure of Git repositories by examining the .git directory—a hidden folder that contains all Git metadata, history, and configuration. The instructor demonstrates how to navigate into .git to understand its contents and emphasizes the critical importance of avoiding direct modifications to this directory. The lesson concludes by illustrating what happens when the .git folder is completely deleted, showing that while project files remain intact, all version control tracking is permanently lost.

Key points

  • The .git directory is a hidden folder containing all Git repository metadata, commit history, branches, and configuration
  • Git manages the .git directory exclusively; users should not manually edit files within it unless they have deep Git knowledge
  • The entire working directory and its version control state are entirely managed by the contents of the .git folder
  • Deleting the .git directory removes all Git tracking from the project while leaving your actual project files untouched
  • Understanding the .git directory structure is essential for comprehending how Git works internally

FAQ

What is the .git directory and why is it important?

The .git directory is a hidden folder that Git creates in your project root. It contains all metadata, commit history, branch information, and configuration needed for version control. Every piece of information about your repository's history is stored within this directory.

Why is it dangerous to modify files inside .git directly?

The .git directory is managed exclusively by Git and contains critical internal structures organized in a specific format. Direct modifications can corrupt your repository, corrupt commits, lose history, or break branch tracking entirely. Only Git commands should be used to modify repository data.

What happens if I accidentally delete the .git folder?

Deleting the .git directory removes all Git version control from your project. Your source files remain unchanged, but all commit history, branches, and tracking information is permanently lost. The directory is no longer a Git repository.