< zurück

weiter >

Minimal contents of a .git folder

von Manuel Strehl

Abgelegt unter

Schlüsselwörter: , ,

The set-up is quite simple. Use git init to get a boilerplate .git folder and then remove as much as possible. Where do we end? Let’s start one by one.

$ git init .
Initialized empty Git repository in /folder/.git/
$ find .git
.git/
.git/refs/
.git/refs/tags/
.git/refs/heads/
.git/config
.git/info/
.git/info/exclude
.git/branches/
.git/description
.git/objects/
.git/objects/pack/
.git/objects/info/
.git/HEAD
.git/hooks/
.git/hooks/prepare-commit-msg.sample
.git/hooks/pre-rebase.sample
.git/hooks/post-update.sample
.git/hooks/pre-applypatch.sample
.git/hooks/pre-commit.sample
.git/hooks/applypatch-msg.sample
.git/hooks/commit-msg.sample
.git/hooks/update.sample

Some things we can remove quite obviously: sample hook scripts, the info/exclude file, since it doesn’t do anything as default, the description file. So we’re left with a much shorter .git folder:

$ rm -fr .git/hooks .git/info .git/description
$ find .git
.git/
.git/refs/
.git/refs/tags/
.git/refs/heads/
.git/config
.git/branches/
.git/objects/
.git/objects/pack/
.git/objects/info/
.git/HEAD
$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

What happens, when we remove too much, e. g., the HEAD file?

$ rm .git/HEAD
$ git status
fatal: Not a git repository (or any of the parent directories): .git

So we can go on and delete stuff, until we hit the above message. We end up with a fairly condensed .git folder:

$ find .git
.git/HEAD
.git/refs/
.git/objects/
$ cat .git/HEAD
ref: refs/heads/master
$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

No config file needed, no sub-folders and so on. If you want to create your own minimal git-init script, it could look like this:

#!/bin/sh
mkdir .git
mkdir .git/refs
mkdir .git/objects
echo 'ref: refs/heads/master' > .git/HEAD

That’s it. (Why someone would want to do this is an entirely different question.)