Git repository without git

Instead of initializing new git repository with “git init” command, it is entirely possible to create a new git repository with basic unix commands. This is how you do it.

Git keeps track of all the details related to a repository in .git directory. The trick is to create this directory with all the items.

First create a directory with a repo name.

$ mkdir test

Then switch to the directory and create the .git directory

$ cd test
$ mkdir .git

Next create a directory called “objects” under .git.

$ mkdir .git/objects

Objects directory is where git store all the content. When a file is added to a git repo, git hashes the file, comes up with a SHA1 hash (a checksum of the content of the file you’re storing plus a header)and stored it under objects directory.

Next step is to create “refs” directory. Refs is how git address commits, it is gits’ internal mechanism of representing branches and tags.

$ mkdir .git/refs
$ mkdir .git/refs/heads

Then create HEAD file. Usually the HEAD file is a symbolic reference to the branch you’re currently on. For a new git repository that would be master.

$ echo "ref: refs/heads/master" > .git/HEAD

Now if we run git status, we can see the new git repository.

$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)