How to Set Up .git
How to Set Up .git 관련
Let’s create a new directory, and run git status
within it:
Alright, so git
seems unhappy as we don’t have a .git
folder. The natural thing to do would be to simply create that directory:
Apparently, creating a .git
directory is just not enough. We need to add some content to that directory.
A git repository has two main components:
- A collection of objects — blobs, trees, and commits.
- A system of naming those objects — called references.
A repository may also contain other things, such as git hooks, but at the very least — it must include objects and references.
Let’s create a directory for the objects at .git\objects
and a directory for the references (in short: refs) at .git\refs
(on UNIX -based systems — .git/objects
and .git/refs
, respectively).
One type of reference is branches. Internally, git
calls branches by the name heads. So we will create a directory for them — .git\refs\heads
.
How does git
know where to start when looking for a commit in the repository? As I explained earlier, it looks for HEAD
, which points to the current active branch (or commit, in some cases).
So, we need to create the HEAD
, which is just a file residing at .git\HEAD
. We can apply the following:
ECHO ref: refs/heads/master > .git\HEAD`
echo "ref: refs/heads/master" > .git/HEAD
⭐ So we now know how HEAD
is implemented — it’s simply a file, and its contents describe what it points to.
Notice that git
believes we are on a branch called master
, even though we haven’t created this branch. As mentioned before, master
is just a name. We could also make git
believe we are on a branch called banana
if we wanted to:
We will switch back to master
for the rest of this post, just to adhere to the normal convention.
Now that we have our .git
directory ready, can we work our way to make a commit (again, without using git add
or git commit
).