The .git folder contains all the information that is necessary for your project in version control and all the information about commits, remote repository address, etc. All of them are present in this folder. It also contains a log that stores your commit history so that you can roll back to history.
This explanation should help beginners to understand the .git folder.
The .git folder is a bit like a magic hat into which you put your current magic show.
When you create a new git repository (git init), everything you organise into a show format is put inside this magic hat and can be 'pulled out' whenever, wherever you want.
After pulling everything out, you can throw everything away when you are finished with the show (i.e. all your files except the .git folder), and you can always pull out exactly the same show at a later date. (As each new show is simply a clone of what is inside the hat).
If you send someone JUST the .git folder, they can always pull out your project files into the same structure (show format) as you put them in.
git add tells the .git folder what is able to be pulled out e.g. a rabbit wearing a tuxedo and holding a cane (or a single file or whole menu bar on your website).
git rm tells the .git folder to stop allowing something to be pulled out of the hat e.g. imagine if you no longer wanted the rabbit to be part of your magic show. (Important to note, that you can still recover a previous version of your show, which would include the rabbit (your 1999 version of your blog with Comic Sans), if you really wanted, but your current show would not include the rabbit if you used git rm).
This is the "thing" which makes your project a "git" repository.
The .git folder is the directory which is created when you do git init (in case of a new project) or you do git clone (in case of pulling a project from somewhere else). Without .git, your project is a local project and not a git project, that means you cannot perform any git operations.
git stores the metadata and object database for the project in this directory like:
Remote information (to which remote server your project is connected)
History of all local commits
Branch information (on which branch is your current project state (HEAD) pointing to)
All logs of all local commits you have ever made (including revert changes)
Technically that .git directory is the Git repository itself. All contents of the repository, including all file versions, tags, branches, etc., are spread across files within this directory.
Things immediately outside .git comprise the working directory, which is an optional accomodation to make working with your Git repository easier. By default working directory reflects the latest commit of your local repository, but you can switch your working directory tree to different commits within the repository, and modify/create/delete files within the working directory before making a new commit.
Without a working tree you can still have a bare Git repository—it consists only of the .git directory (normally named <something>.git in this scenario) and nothing else. It’s not commonly used except on Git servers.