Click here to Skip to main content
13,191,400 members (73,451 online)
Click here to Skip to main content
Add your own
alternative version

Stats

4.2K views
4 bookmarked
Posted 26 Dec 2015

Git: How to Create Repository From Scratch

, 26 Dec 2015
Rate this:
Please Sign up or sign in to vote.
This tip describes steps for creating git repository without git init command.

Introduction

I believe this tip will useful for all who use git and want to know more about git internal details.

I aimed to create minimal valid ".git" directory. At the end of my steps, "git status" command should be happy with handmade structure of ".git" directory.

Background

Internal details are very useful to keep in mind when using Git.

Creating Repository

First of all, create "repo" directory. Inside this directory, we will create several folders and one file. And after that, git will be satisfied.

Before start, we ask git about "repo" with "status" command.

git status

We get the following answer:

fatal: Not a git repository (or any of the parent directories): .git

As you can see, git isn't happy.

So we will try to make git happy about our directory.

  1. Create ".git" directory inside "repo". Our repository will located here.
  2. Create "objects" directory inside ".git". This directory will contain our commits.
  3. Create "refs" directory inside ".git". This directory will contain branches.
  4. And last one but not the least. Create file "HEAD" inside ".git" with content "ref: refs/heads/master". This is a pointer on current branch.

It's all what we need.

Ask again git about "repo".

git status

Git's answer on it.

On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)

Git now happy!

We've created git repository without "init" command.

History

  • 27.12.2015 Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dmitry Handin
Software Developer (Senior)
Russian Federation Russian Federation
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171017.1 | Last Updated 26 Dec 2015
Article Copyright 2015 by Dmitry Handin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid