What is the folder called .git
?
It\'s created in a repository. What is contained within it and why is created?
Basiclly, it means your dir is handled by Git (Git repository). If you move it somewhere else (or delete it), you'll face something like:
fatal: Not a git repository (or any of the parent directories): .git
every time you use 'git *' command there.
You can move the .git directory somewhere else using:
git --git-dir=/myproject_path/myproject.git log --oneline
Or:
export GIT_DIR=/myproject_path/myproject.git
But i don't recommend doing it. Pay attention that it is only 1 folder, unlike SVN.
It holds all relevant info for GIT to handle your code, like the position of the HEAD, hooks to apply before/after commit/push and some other files.
Maybe most "famous" file inside is the config file which holds all your branches info.
Recommend to read here more info.
The .git
folder is the directory which is created when you do git init
(in the case of a new project) or you do git clone
(in the case of pulling a project from somewhere else). This is the "thing" which makes your project a "git" repository. 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:
To know more, check the official documentation from git: https://git-scm.com/book/en/v1/Git-Basics-Getting-a-Git-Repository
.git is initialized by git init
.
.git contains all information required for version control. If you want to clone your repo, copy .git is enough.
4 sub-directories:
exclude
file for ignored patterns4 files:
Here "object" includes:
.git
directoryIf you were curious — „ —, this resource might be of help
http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html
The basic structure looks like this:
. |-- COMMIT_EDITMSG |-- FETCH_HEAD |-- HEAD |-- ORIG_HEAD |-- branches |-- config |-- description |-- hooks | |-- applypatch-msg | |-- commit-msg | |-- post-commit
... continues on the site
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.
For more info, you can check the official website of git.
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
).