|
| 1 | +Create and access git repositories |
| 2 | +================================== |
| 3 | + |
| 4 | +gitlib provides methods to initialize new repositories. |
| 5 | + |
| 6 | +Create a repository |
| 7 | +------------------- |
| 8 | + |
| 9 | +To initialize a new repository, use method `Admin::init`. |
| 10 | + |
| 11 | +```php |
| 12 | +// Initialize a bare repository |
| 13 | +$repository = Gitonomy\Git\Admin::init('/path/to/repository'); |
| 14 | + |
| 15 | +// Initialize a non-bare repository |
| 16 | +$repository = Gitonomy\Git\Admin::init('/path/to/repository', false); |
| 17 | +``` |
| 18 | + |
| 19 | +Default behavior is to create a bare repository. If you want to |
| 20 | +initialize a repository with a working copy,pass `false` as third |
| 21 | +argument of Repository constructor. |
| 22 | + |
| 23 | +Cloning repositories |
| 24 | +-------------------- |
| 25 | + |
| 26 | +You can clone a repository from an URL by doing: |
| 27 | + |
| 28 | +```php |
| 29 | +// Clone to a bare repository |
| 30 | +$repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git'); |
| 31 | + |
| 32 | +// Clone to a non-bare repository |
| 33 | +$repository = Gitonomy\Git\Admin::cloneTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', false); |
| 34 | +``` |
| 35 | + |
| 36 | +Default behavior is to clone in a bare repository. |
| 37 | + |
| 38 | +You can also clone a repository and point it to a specific branch. In a |
| 39 | +non-bare repository, this branch will be checked out: |
| 40 | + |
| 41 | +```php |
| 42 | +// Clone to a bare repository |
| 43 | +$repository = Gitonomy\Git\Admin::cloneBranchTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', 'a-branch'); |
| 44 | + |
| 45 | +// Clone to a non-bare repository |
| 46 | +$repository = Gitonomy\Git\Admin::cloneBranchTo('/tmp/gitlib', 'https://github.com/gitonomy/gitlib.git', 'a-branch' false); |
| 47 | +``` |
| 48 | + |
| 49 | +Clone a Repository object |
| 50 | +------------------------- |
| 51 | + |
| 52 | +If you already have a Repository instance and want to clone it, you can |
| 53 | +use this shortcut: |
| 54 | + |
| 55 | +```php |
| 56 | +$new = $repository->cloneTo('/tmp/clone'); |
| 57 | +``` |
| 58 | + |
| 59 | +Mirror a repository |
| 60 | +------------------- |
| 61 | + |
| 62 | +If you want to mirror fully a repository and all references, use the |
| 63 | +`mirrorTo` method. This method takes only two arguments, where to mirror |
| 64 | +and what to mirror: |
| 65 | + |
| 66 | +```php |
| 67 | +// Mirror to a bare repository |
| 68 | +$mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', 'https://github.com/gitonomy/gitlib.git'); |
| 69 | + |
| 70 | +// Mirror to a non-bare repository |
| 71 | +$mirror = Gitonomy\Git\Admin::mirrorTo('/tmp/mirror', 'https://github.com/gitonomy/gitlib.git', false); |
| 72 | +``` |
| 73 | + |
| 74 | +### References |
| 75 | + |
| 76 | +- <http://linux.die.net/man/1/git-init> |
| 77 | +- <http://linux.die.net/man/1/git-clone> |
0 commit comments