Create and access git repositories

gitlib provides methods to initialize new repositories.

Create a repository

To initialize a new repository, use method Admin::init.

// Initialize a bare repository
$repository = Gitonomy\Git\Admin::init('/path/to/repository');

// Initialize a non-bare repository
$repository = Gitonomy\Git\Admin::init('/path/to/repository', false);

Default behavior is to create a bare repository. If you want to initialize a repository with a working copy,pass false as third argument of Repository constructor.

Cloning repositories

You can clone a repository from an URL by doing:

// Clone to a bare repository
$repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', '');

// Clone to a non-bare repository
$repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', '', false);

Default behavior is to clone in a bare repository.

Clone a Repository object

If you already have a Repository instance and want to clone it, you can use this shortcut:

$new = $repository->cloneTo('/tmp/clone');

Mirror a repository

If you want to mirror fully a repository and all references, use the mirrorTo method. This method takes only two arguments, where to mirror and what to mirror:

// Mirror to a bare repository
$mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', '');

// Mirror to a non-bare repository
$mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', '', false);