Today afternoon I was going through the documentation of git to learn more about git commands. All of a sudden I stumbled upon a valuable piece of information. When we create a git repository using the git init
command,
a new folder called .git gets created which contains the following directories and files. The .git folder appears following when there's zero staging and commits.
The moment you make your first commit, the .git folder appears like this with some extra files and folders.
There was a section in the documentation that described what each file in the .git folder stores. I actually went through the text and decided to share what I learned. So, let's get started!!!
1.hooks
- It stores client-side or server-side hook scripts. So, basically, we can say that hooks are scripts. Whenever an event occurs in a git repository, these scripts automatically execute. For example, when we perform a commit operation one of the scripts in the hooks
folder executes to complete the commit operation. I actually experimented by deleting the hooks
folder from .git but it still worked the same without any malfunction.
2.info
- It stores the information about everything that you put into the .gitignore file.
3.objects
- It is a database for your repository. Everything that we do inside our repository like the creation of the new file, committing, etc that information is stored in the objects
directory. I experimented and found that every time you make a commit new subdirectories get created in the objects
directory.If you delete your objects
folder all of your commit info will be gone. I deleted my object
directory where and hit the git log
command it showed me something like this- all my commit info was lost.
4.refs
- This directory stores information about the head and tags.
5.config
- It is used to store configuration for the repository. I deleted the config file and ran the git status
command it showed me something like this
6.Description
- It is used by the GitWeb program.
7.HEAD
- It stores the information about the branch you have currently checkout to.
I figured out hooks
, objects
, and config
are most sensible so better not touch them.