aboutsummaryrefslogblamecommitdiffstats
path: root/library/kzykhys/git/README.md
blob: b2f6635af73d6d2e87eea2f65f045b0f5985935c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347


































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                                                          
PHPGit - A Git wrapper for PHP5.3+
==================================

[![Latest Unstable Version](https://poser.pugx.org/kzykhys/git/v/unstable.png)](https://packagist.org/packages/kzykhys/git)
[![Build Status](https://travis-ci.org/kzykhys/PHPGit.png?branch=master)](https://travis-ci.org/kzykhys/PHPGit)
[![Coverage Status](https://coveralls.io/repos/kzykhys/PHPGit/badge.png)](https://coveralls.io/r/kzykhys/PHPGit)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/04f10b57-a113-47ad-8dda-9a6dacbb079f/mini.png)](https://insight.sensiolabs.com/projects/04f10b57-a113-47ad-8dda-9a6dacbb079f)

Requirements
------------

* PHP5.3
* Git

Installation
------------

Update your composer.json and run `composer update`

``` json
{
    "require": {
        "kzykhys/git": "dev-master"
    }
}
```

Basic Usage
-----------

``` php
<?php

require __DIR__ . '/vendor/autoload.php';

$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$git->remote->add('production', 'git://example.com/your/repo.git');
$git->add('README.md');
$git->commit('Adds README.md');
$git->checkout('release');
$git->merge('master');
$git->push();
$git->push('production', 'release');
$git->tag->create('v1.0.1', 'release');

foreach ($git->tree('release') as $object) {
    if ($object['type'] == 'blob') {
        echo $git->show($object['file']);
    }
}
```

API
---

### Git commands

* [git add](#git-add)
    * $git->[add](#git-addstringarraytraversable-file-array-options--)(_string|array|\Traversable_ $file, _array_ $options = [])
* [git archive](#git-archive)
    * $git->[archive](#git-archivestring-file-string-tree--null-stringarraytraversable-path--null-array-options--)(_string_ $file, _string_ $tree = null, _string|array|\Traversable_ $path = null, _array_ $options = [])
* [git branch](#git-branch)
    * $git->[branch](#git-brancharray-options--)(_array_ $options = [])
    * $git->branch->[create](#git-branch-createstring-branch-string-startpoint--null-array-options--)(_string_ $branch, _string_ $startPoint = null, _array_ $options = [])
    * $git->branch->[move](#git-branch-movestring-branch-string-newbranch-array-options--)(_string_ $branch, _string_ $newBranch, _array_ $options = [])
    * $git->branch->[delete](#git-branch-deletestring-branch-array-options--)(_string_ $branch, _array_ $options = [])
* [git cat-file](#git-cat-file)
    * $git->cat->[blob](#git-cat-blobstring-object)(_string_ $object)
    * $git->cat->[type](#git-cat-typestring-object)(_string_ $object)
    * $git->cat->[size](#git-cat-sizestring-object)(_string_ $object)
* [git checkout](#git-checkout)
    * $git->[checkout](#git-checkoutstring-branch-array-options--)(_string_ $branch, _array_ $options = [])
    * $git->checkout->[create](#git-checkout-createstring-branch-string-startpoint--null-array-options--)(_string_ $branch, _string_ $startPoint = null, _array_ $options = [])
    * $git->checkout->[orphan](#git-checkout-orphanstring-branch-string-startpoint--null-array-options--)(_string_ $branch, _string_ $startPoint = null, _array_ $options = [])
* [git clone](#git-clone)
    * $git->[clone](#git-clonestring-repository-string-path--null-array-options--)(_string_ $repository, _string_ $path = null, _array_ $options = [])
* [git commit](#git-commit)
    * $git->[commit](#git-commitstring-message-array-options--)(_string_ $message, _array_ $options = [])
* [git config](#git-config)
    * $git->[config](#git-configarray-options--)(_array_ $options = [])
    * $git->config->[set](#git-config-setstring-name-string-value-array-options--)(_string_ $name, _string_ $value, _array_ $options = [])
    * $git->config->[add](#git-config-addstring-name-string-value-array-options--)(_string_ $name, _string_ $value, _array_ $options = [])
* [git describe](#git-describe)
    * $git->[describe](#git-describestring-committish--null-array-options--)(_string_ $committish = null, _array_ $options = [])
    * $git->describe->[tags](#git-describe-tagsstring-committish--null-array-options--)(_string_ $committish = null, _array_ $options = [])
* [git fetch](#git-fetch)
    * $git->[fetch](#git-fetchstring-repository-string-refspec--null-array-options--)(_string_ $repository, _string_ $refspec = null, _array_ $options = [])
    * $git->fetch->[all](#git-fetch-allarray-options--)(_array_ $options = [])
* [git init](#git-init)
    * $git->[init](#git-initstring-path-array-options--)(_string_ $path, _array_ $options = [])
* [git log](#git-log)
    * $git->[log](#git-logstring-revrange---string-path--null-array-options--)(_string_ $revRange = '', _string_ $path = null, _array_ $options = [])
* [git merge](#git-merge)
    * $git->[merge](#git-mergestringarraytraversable-commit-string-message--null-array-options--)(_string|array|\Traversable_ $commit, _string_ $message = null, _array_ $options = [])
    * $git->merge->[abort](#git-merge-abort)()
* [git mv](#git-mv)
    * $git->[mv](#git-mvstringarrayiterator-source-string-destination-array-options--)(_string|array|\Iterator_ $source, _string_ $destination, _array_ $options = [])
* [git pull](#git-pull)
    * $git->[pull](#git-pullstring-repository--null-string-refspec--null-array-options--)(_string_ $repository = null, _string_ $refspec = null, _array_ $options = [])
* [git push](#git-push)
    * $git->[push](#git-pushstring-repository--null-string-refspec--null-array-options--)(_string_ $repository = null, _string_ $refspec = null, _array_ $options = [])
* [git rebase](#git-rebase)
    * $git->[rebase](#git-rebasestring-upstream--null-string-branch--null-array-options--)(_string_ $upstream = null, _string_ $branch = null, _array_ $options = [])
    * $git->rebase->[continues](#git-rebase-continues)()
    * $git->rebase->[abort](#git-rebase-abort)()
    * $git->rebase->[skip](#git-rebase-skip)()
* [git remote](#git-remote)
    * $git->[remote](#git-remote)()
    * $git->remote->[add](#git-remote-addstring-name-string-url-array-options--)(_string_ $name, _string_ $url, _array_ $options = [])
    * $git->remote->[rename](#git-remote-renamestring-name-string-newname)(_string_ $name, _string_ $newName)
    * $git->remote->[rm](#git-remote-rmstring-name)(_string_ $name)
    * $git->remote->[show](#git-remote-showstring-name)(_string_ $name)
    * $git->remote->[prune](#git-remote-prunestring-name--null)(_string_ $name = null)
    * $git->remote->[head](#git-remote-headstring-name-string-branch--null)(_string_ $name, _string_ $branch = null)
    * $git->remote->head->[set](#git-remote-head-setstring-name-string-branch)(_string_ $name, _string_ $branch)
    * $git->remote->head->[delete](#git-remote-head-deletestring-name)(_string_ $name)
    * $git->remote->head->[remote](#git-remote-head-remotestring-name)(_string_ $name)
    * $git->remote->[branches](#git-remote-branchesstring-name-array-branches)(_string_ $name, _array_ $branches)
    * $git->remote->branches->[set](#git-remote-branches-setstring-name-array-branches)(_string_ $name, _array_ $branches)
    * $git->remote->branches->[add](#git-remote-branches-addstring-name-array-branches)(_string_ $name, _array_ $branches)
    * $git->remote->[url](#git-remote-urlstring-name-string-newurl-string-oldurl--null-array-options--)(_string_ $name, _string_ $newUrl, _string_ $oldUrl = null, _array_ $options = [])
    * $git->remote->url->[set](#git-remote-url-setstring-name-string-newurl-string-oldurl--null-array-options--)(_string_ $name, _string_ $newUrl, _string_ $oldUrl = null, _array_ $options = [])
    * $git->remote->url->[add](#git-remote-url-addstring-name-string-newurl-array-options--)(_string_ $name, _string_ $newUrl, _array_ $options = [])
    * $git->remote->url->[delete](#git-remote-url-deletestring-name-string-url-array-options--)(_string_ $name, _string_ $url, _array_ $options = [])
* [git reset](#git-reset)
    * $git->[reset](#git-resetstringarraytraversable-paths-string-commit--null)(_string|array|\Traversable_ $paths, _string_ $commit = null)
    * $git->reset->[soft](#git-reset-softstring-commit--null)(_string_ $commit = null)
    * $git->reset->[mixed](#git-reset-mixedstring-commit--null)(_string_ $commit = null)
    * $git->reset->[hard](#git-reset-hardstring-commit--null)(_string_ $commit = null)
    * $git->reset->[merge](#git-reset-mergestring-commit--null)(_string_ $commit = null)
    * $git->reset->[keep](#git-reset-keepstring-commit--null)(_string_ $commit = null)
    * $git->reset->[mode](#git-reset-modestring-mode-string-commit--null)(_string_ $mode, _string_ $commit = null)
* [git rm](#git-rm)
    * $git->[rm](#git-rmstringarraytraversable-file-array-options--)(_string|array|\Traversable_ $file, _array_ $options = [])
    * $git->rm->[cached](#git-rm-cachedstringarraytraversable-file-array-options--)(_string|array|\Traversable_ $file, _array_ $options = [])
* [git shortlog](#git-shortlog)
    * $git->[shortlog](#git-shortlogstringarraytraversable-commits--head)(_string|array|\Traversable_ $commits = HEAD)
    * $git->shortlog->[summary](#git-shortlog-summarystring-commits--head)(_string_ $commits = HEAD)
* [git show](#git-show)
    * $git->[show](#git-showstring-object-array-options--)(_string_ $object, _array_ $options = [])
* [git stash](#git-stash)
    * $git->[stash](#git-stash)()
    * $git->stash->[save](#git-stash-savestring-message--null-array-options--)(_string_ $message = null, _array_ $options = [])
    * $git->stash->[lists](#git-stash-listsarray-options--)(_array_ $options = [])
    * $git->stash->[show](#git-stash-showstring-stash--null)(_string_ $stash = null)
    * $git->stash->[drop](#git-stash-dropstring-stash--null)(_string_ $stash = null)
    * $git->stash->[pop](#git-stash-popstring-stash--null-array-options--)(_string_ $stash = null, _array_ $options = [])
    * $git->stash->[apply](#git-stash-applystring-stash--null-array-options--)(_string_ $stash = null, _array_ $options = [])
    * $git->stash->[branch](#git-stash-branchstring-name-string-stash--null)(_string_ $name, _string_ $stash = null)
    * $git->stash->[clear](#git-stash-clear)()
    * $git->stash->[create](#git-stash-create)()
* [git status](#git-status)
    * $git->[status](#git-statusarray-options--)(_array_ $options = [])
* [git tag](#git-tag)
    * $git->[tag](#git-tag)()
    * $git->tag->[create](#git-tag-createstring-tag-string-commit--null-array-options--)(_string_ $tag, _string_ $commit = null, _array_ $options = [])
    * $git->tag->[delete](#git-tag-deletestringarraytraversable-tag)(_string|array|\Traversable_ $tag)
    * $git->tag->[verify](#git-tag-verifystringarraytraversable-tag)(_string|array|\Traversable_ $tag)
* [git ls-tree](#git-ls-tree)
    * $git->[tree](#git-treestring-branch--master-string-path--)(_string_ $branch = master, _string_ $path = '')

* * * * *

### git add

#### $git->add(_string|array|\Traversable_ $file, _array_ $options = [])

Add file contents to the index

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->add('file.txt');
$git->add('file.txt', ['force' => false, 'ignore-errors' => false);
```

##### Options

- **force**          (_boolean_) Allow adding otherwise ignored files
- **ignore-errors**  (_boolean_) Do not abort the operation

* * * * *

### git archive

#### $git->archive(_string_ $file, _string_ $tree = null, _string|array|\Traversable_ $path = null, _array_ $options = [])

Create an archive of files from a named tree

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->archive('repo.zip', 'master', null, ['format' => 'zip']);
```

##### Options

- **format** (_boolean_) Format of the resulting archive: tar or zip
- **prefix** (_boolean_) Prepend prefix/ to each filename in the archive

* * * * *

### git branch

#### $git->branch(_array_ $options = [])

Returns an array of both remote-tracking branches and local branches

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$branches = $git->branch();
```

##### Output Example

```
[
    'master' => ['current' => true, 'name' => 'master', 'hash' => 'bf231bb', 'title' => 'Initial Commit'],
    'origin/master' => ['current' => false, 'name' => 'origin/master', 'alias' => 'remotes/origin/master']
]
```

##### Options

- **all**     (_boolean_) List both remote-tracking branches and local branches
- **remotes** (_boolean_) List the remote-tracking branches

#### $git->branch->create(_string_ $branch, _string_ $startPoint = null, _array_ $options = [])

Creates a new branch head named **$branch** which points to the current HEAD, or **$startPoint** if given

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->create('bugfix');              // from current HEAD
$git->branch->create('patch-1', 'a092bf7s'); // from commit
$git->branch->create('1.0.x-fix', 'v1.0.2'); // from tag
```

##### Options

- **force**   (_boolean_) Reset **$branch**  to **$startPoint** if **$branch** exists already

#### $git->branch->move(_string_ $branch, _string_ $newBranch, _array_ $options = [])

Move/rename a branch and the corresponding reflog

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->move('bugfix', '2.0');
```

##### Options

- **force**   (_boolean_) Move/rename a branch even if the new branch name already exists

#### $git->branch->delete(_string_ $branch, _array_ $options = [])

Delete a branch

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->delete('2.0');
```

The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream.

##### Options

- **force**   (_boolean_) Delete a branch irrespective of its merged status

* * * * *

### git cat-file

#### $git->cat->blob(_string_ $object)

Returns the contents of blob object

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$contents = $git->cat->blob('e69de29bb2d1d6434b8b29ae775ad8');
```

#### $git->cat->type(_string_ $object)

Returns the object type identified by **$object**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$type = $git->cat->type('e69de29bb2d1d6434b8b29ae775ad8');
```

#### $git->cat->size(_string_ $object)

Returns the object size identified by **$object**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$type = $git->cat->size('e69de29bb2d1d6434b8b29ae775ad8');
```

* * * * *

### git checkout

#### $git->checkout(_string_ $branch, _array_ $options = [])

Switches branches by updating the index, working tree, and HEAD to reflect the specified branch or commit

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout('develop');
```

##### Options

- **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD
- **merge** (_boolean_) Merges local modification

#### $git->checkout->create(_string_ $branch, _string_ $startPoint = null, _array_ $options = [])

Create a new branch and checkout

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->create('patch-1');
$git->checkout->create('patch-2', 'develop');
```

##### Options

- **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD

#### $git->checkout->orphan(_string_ $branch, _string_ $startPoint = null, _array_ $options = [])

Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->orphan('gh-pages');
```

##### Options

- **force** (_boolean_) Proceed even if the index or the working tree differs from HEAD

* * * * *

### git clone

#### $git->clone(_string_ $repository, _string_ $path = null, _array_ $options = [])

Clone a repository into a new directory

``` php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
```

##### Options

- **shared** (_boolean_) Starts out without any object of its own
- **bare**   (_boolean_) Make a bare GIT repository

* * * * *

### git commit

#### $git->commit(_string_ $message, _array_ $options = [])

Record changes to the repository

``` php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$git->add('README.md');
$git->commit('Fixes README.md');
```

##### Options

- **all**           (_boolean_) Stage files that have been modified and deleted
- **reuse-message** (_string_)  Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit
- **squash**        (_string_)  Construct a commit message for use with rebase --autosquash
- **author**        (_string_)  Override the commit author
- **date**          (_string_)  Override the author date used in the commit
- **cleanup**       (_string_)  Can be one of verbatim, whitespace, strip, and default
- **amend**         (_boolean_) Used to amend the tip of the current branch

* * * * *

### git config

#### $git->config(_array_ $options = [])

Returns all variables set in config file


##### Options

- **global** (_boolean_) Read or write configuration options for the current user
- **system** (_boolean_) Read or write configuration options for all users on the current machine

#### $git->config->set(_string_ $name, _string_ $value, _array_ $options = [])

Set an option

##### Options

- **global** (_boolean_) Read or write configuration options for the current user
- **system** (_boolean_) Read or write configuration options for all users on the current machine

#### $git->config->add(_string_ $name, _string_ $value, _array_ $options = [])

Adds a new line to the option without altering any existing values

##### Options

- **global** (_boolean_) Read or write configuration options for the current user
- **system** (_boolean_) Read or write configuration options for all users on the current machine

* * * * *

### git describe

#### $git->describe(_string_ $committish = null, _array_ $options = [])

Returns the most recent tag that is reachable from a commit

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->tag->create('v1.0.0');
$git->commit('Fixes #14');
echo $git->describe('HEAD', ['tags' => true]);
```

##### Output Example

```
v1.0.0-1-g7049efc
```

##### Options

- **all**    (_boolean_) Enables matching any known branch, remote-tracking branch, or lightweight tag
- **tags**   (_boolean_) Enables matching a lightweight (non-annotated) tag
- **always** (_boolean_) Show uniquely abbreviated commit object as fallback

#### $git->describe->tags(_string_ $committish = null, _array_ $options = [])

Equivalent to $git->describe($committish, ['tags' => true]);

* * * * *

### git fetch

#### $git->fetch(_string_ $repository, _string_ $refspec = null, _array_ $options = [])

Fetches named heads or tags from one or more other repositories, along with the objects necessary to complete them

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'git://your/repo.git');
$git->fetch('origin');
```

##### Options

- **append** (_boolean_) Append ref names and object names of fetched refs to the existing contents of .git/FETCH_HEAD
- **keep**   (_boolean_) Keep downloaded pack
- **prune**  (_boolean_) After fetching, remove any remote-tracking branches which no longer exist on the remote

#### $git->fetch->all(_array_ $options = [])

Fetch all remotes

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'git://your/repo.git');
$git->remote->add('release', 'git://your/another_repo.git');
$git->fetch->all();
```

##### Options

- **append** (_boolean_) Append ref names and object names of fetched refs to the existing contents of .git/FETCH_HEAD
- **keep**   (_boolean_) Keep downloaded pack
- **prune**  (_boolean_) After fetching, remove any remote-tracking branches which no longer exist on the remote

* * * * *

### git init

#### $git->init(_string_ $path, _array_ $options = [])

Create an empty git repository or reinitialize an existing one

``` php
$git = new PHPGit\Git();
$git->init('/path/to/repo1');
$git->init('/path/to/repo2', array('shared' => true, 'bare' => true));
```

##### Options

- **shared** (_boolean_) Specify that the git repository is to be shared amongst several users
- **bare**   (_boolean_) Create a bare repository

* * * * *

### git log

#### $git->log(_string_ $revRange = '', _string_ $path = null, _array_ $options = [])

Returns the commit logs

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$logs = $git->log(array('limit' => 10));
```

##### Output Example

``` php
[
    0 => [
        'hash'  => '1a821f3f8483747fd045eb1f5a31c3cc3063b02b',
        'name'  => 'John Doe',
        'email' => 'john@example.com',
        'date'  => 'Fri Jan 17 16:32:49 2014 +0900',
        'title' => 'Initial Commit'
    ],
    1 => [
        //...
    ]
]
```

##### Options

- **limit** (_integer_) Limits the number of commits to show
- **skip**  (_integer_) Skip number commits before starting to show the commit output

* * * * *

### git merge

#### $git->merge(_string|array|\Traversable_ $commit, _string_ $message = null, _array_ $options = [])

Incorporates changes from the named commits into the current branch

```php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->merge('1.0');
$git->merge('1.1', 'Merge message', ['strategy' => 'ours']);
```

##### Options

- **no-ff**               (_boolean_) Do not generate a merge commit if the merge resolved as a fast-forward, only update the branch pointer
- **rerere-autoupdate**   (_boolean_) Allow the rerere mechanism to update the index with the result of auto-conflict resolution if possible
- **squash**              (_boolean_) Allows you to create a single commit on top of the current branch whose effect is the same as merging another branch
- **strategy**            (_string_)  Use the given merge strategy
- **strategy-option**     (_string_)  Pass merge strategy specific option through to the merge strategy

#### $git->merge->abort()

Abort the merge process and try to reconstruct the pre-merge state

```php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
try {
    $git->merge('dev');
} catch (PHPGit\Exception\GitException $e) {
    $git->merge->abort();
}
```

* * * * *

### git mv

#### $git->mv(_string|array|\Iterator_ $source, _string_ $destination, _array_ $options = [])

Move or rename a file, a directory, or a symlink

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->mv('UPGRADE-1.0.md', 'UPGRADE-1.1.md');
```

##### Options

- **force** (_boolean_) Force renaming or moving of a file even if the target exists

* * * * *

### git pull

#### $git->pull(_string_ $repository = null, _string_ $refspec = null, _array_ $options = [])

Fetch from and merge with another repository or a local branch

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->pull('origin', 'master');
```

* * * * *

### git push

#### $git->push(_string_ $repository = null, _string_ $refspec = null, _array_ $options = [])

Update remote refs along with associated objects

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->push('origin', 'master');
```

* * * * *

### git rebase

#### $git->rebase(_string_ $upstream = null, _string_ $branch = null, _array_ $options = [])

Forward-port local commits to the updated upstream head

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->fetch('origin');
$git->rebase('origin/master');
```

##### Options

- **onto**          (_string_)  Starting point at which to create the new commits
- **no-verify**     (_boolean_) Bypasses the pre-rebase hook
- **force-rebase**  (_boolean_) Force the rebase even if the current branch is a descendant of the commit you are rebasing onto

#### $git->rebase->continues()

Restart the rebasing process after having resolved a merge conflict

#### $git->rebase->abort()

Abort the rebase operation and reset HEAD to the original branch

#### $git->rebase->skip()

Restart the rebasing process by skipping the current patch

* * * * *

### git remote

#### $git->remote()

Returns an array of existing remotes

``` php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$remotes = $git->remote();
```

##### Output Example

``` php
[
    'origin' => [
        'fetch' => 'https://github.com/kzykhys/Text.git',
        'push'  => 'https://github.com/kzykhys/Text.git'
    ]
]
```

#### $git->remote->add(_string_ $name, _string_ $url, _array_ $options = [])

Adds a remote named **$name** for the repository at **$url**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->fetch('origin');
```

##### Options

- **tags**    (_boolean_) With this option, `git fetch <name>` imports every tag from the remote repository
- **no-tags** (_boolean_) With this option, `git fetch <name>` does not import tags from the remote repository

#### $git->remote->rename(_string_ $name, _string_ $newName)

Rename the remote named **$name** to **$newName**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->rename('origin', 'upstream');
```

#### $git->remote->rm(_string_ $name)

Remove the remote named **$name**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->rm('origin');
```

#### $git->remote->show(_string_ $name)

Gives some information about the remote **$name**

``` php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
echo $git->remote->show('origin');
```

##### Output Example

```
\* remote origin
  Fetch URL: https://github.com/kzykhys/Text.git
  Push  URL: https://github.com/kzykhys/Text.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
```

#### $git->remote->prune(_string_ $name = null)

Deletes all stale remote-tracking branches under **$name**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->prune('origin');
```

#### $git->remote->head(_string_ $name, _string_ $branch = null)

Alias of set()

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head('origin');
```

#### $git->remote->head->set(_string_ $name, _string_ $branch)

Sets the default branch for the named remote

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->set('origin');
```

#### $git->remote->head->delete(_string_ $name)

Deletes the default branch for the named remote

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->delete('origin');
```

#### $git->remote->head->remote(_string_ $name)

Determine the default branch by querying remote

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->remote('origin');
```

#### $git->remote->branches(_string_ $name, _array_ $branches)

Alias of set()

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches('origin', array('master', 'develop'));
```

#### $git->remote->branches->set(_string_ $name, _array_ $branches)

Changes the list of branches tracked by the named remote

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches->set('origin', array('master', 'develop'));
```

#### $git->remote->branches->add(_string_ $name, _array_ $branches)

Adds to the list of branches tracked by the named remote

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches->add('origin', array('master', 'develop'));
```

#### $git->remote->url(_string_ $name, _string_ $newUrl, _string_ $oldUrl = null, _array_ $options = [])

Alias of set()

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url('origin', 'https://github.com/text/Text.git');
```

##### Options

- **push** (_boolean_) Push URLs are manipulated instead of fetch URLs

#### $git->remote->url->set(_string_ $name, _string_ $newUrl, _string_ $oldUrl = null, _array_ $options = [])

Sets the URL remote to $newUrl

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url->set('origin', 'https://github.com/text/Text.git');
```

##### Options

- **push** (_boolean_) Push URLs are manipulated instead of fetch URLs

#### $git->remote->url->add(_string_ $name, _string_ $newUrl, _array_ $options = [])

Adds new URL to remote

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url->add('origin', 'https://github.com/text/Text.git');
```

##### Options

- **push** (_boolean_) Push URLs are manipulated instead of fetch URLs

#### $git->remote->url->delete(_string_ $name, _string_ $url, _array_ $options = [])

Deletes all URLs matching regex $url

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->url->delete('origin', 'https://github.com');
```

##### Options

- **push** (_boolean_) Push URLs are manipulated instead of fetch URLs

* * * * *

### git reset

#### $git->reset(_string|array|\Traversable_ $paths, _string_ $commit = null)

Resets the index entries for all **$paths** to their state at **$commit**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset();
```

#### $git->reset->soft(_string_ $commit = null)

Resets the current branch head to **$commit**

Does not touch the index file nor the working tree at all (but resets the head to **$commit**,
just like all modes do).
This leaves all your changed files "Changes to be committed", as git status would put it.

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->soft();
```

#### $git->reset->mixed(_string_ $commit = null)

Resets the current branch head to **$commit**

Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit)
and reports what has not been updated. This is the default action.

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mixed();
```

#### $git->reset->hard(_string_ $commit = null)

Resets the current branch head to **$commit**

Resets the index and working tree. Any changes to tracked files in the working tree since **$commit** are discarded

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->hard();
```

#### $git->reset->merge(_string_ $commit = null)

Resets the current branch head to **$commit**

Resets the index and updates the files in the working tree that are different between **$commit** and HEAD,
but keeps those which are different between the index and working tree
(i.e. which have changes which have not been added). If a file that is different between **$commit** and
the index has unstaged changes, reset is aborted

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->merge();
```

#### $git->reset->keep(_string_ $commit = null)

Resets the current branch head to **$commit**

Resets index entries and updates files in the working tree that are different between **$commit** and HEAD.
If a file that is different between **$commit** and HEAD has local changes, reset is aborted.

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->keep();
```

#### $git->reset->mode(_string_ $mode, _string_ $commit = null)

Resets the current branch head to **$commit**

Possibly updates the index (resetting it to the tree of **$commit**) and the working tree depending on **$mode**

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mode('hard');
```

* * * * *

### git rm

#### $git->rm(_string|array|\Traversable_ $file, _array_ $options = [])

Remove files from the working tree and from the index

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->rm('CHANGELOG-1.0-1.1.txt', ['force' => true]);
```

##### Options

- **force**     (_boolean_) Override the up-to-date check
- **cached**    (_boolean_) Unstage and remove paths only from the index
- **recursive** (_boolean_) Allow recursive removal when a leading directory name is given

#### $git->rm->cached(_string|array|\Traversable_ $file, _array_ $options = [])

Equivalent to $git->rm($file, ['cached' => true]);

##### Options

- **force**     (_boolean_) Override the up-to-date check
- **recursive** (_boolean_) Allow recursive removal when a leading directory name is given

* * * * *

### git shortlog

#### $git->shortlog(_string|array|\Traversable_ $commits = HEAD)

Summarize 'git log' output

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$shortlog = $git->shortlog();
```

##### Output Example

``` php
[
    'John Doe <john@example.com>' => [
        0 => ['commit' => '589de67', 'date' => new \DateTime('2014-02-10 12:56:15 +0300'), 'subject' => 'Update README'],
        1 => ['commit' => '589de67', 'date' => new \DateTime('2014-02-15 12:56:15 +0300'), 'subject' => 'Update README'],
    ],
    //...
]
```

#### $git->shortlog->summary(_string_ $commits = HEAD)

Suppress commit description and provide a commit count summary only

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$shortlog = $git->shortlog->summary();
```

##### Output Example

``` php
[
    'John Doe <john@example.com>' => 153,
    //...
]
```

* * * * *

### git show

#### $git->show(_string_ $object, _array_ $options = [])

Shows one or more objects (blobs, trees, tags and commits)

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
echo $git->show('3ddee587e209661c8265d5bfd0df999836f6dfa2');
```

##### Options

- **format**        (_string_)  Pretty-print the contents of the commit logs in a given format, where <format> can be one of oneline, short, medium, full, fuller, email, raw and format:<string>
- **abbrev-commit** (_boolean_) Instead of showing the full 40-byte hexadecimal commit object name, show only a partial prefix

* * * * *

### git stash

#### $git->stash()

Save your local modifications to a new stash, and run git reset --hard to revert them

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash();
```

#### $git->stash->save(_string_ $message = null, _array_ $options = [])

Save your local modifications to a new stash, and run git reset --hard to revert them.

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->save('My stash');
```

#### $git->stash->lists(_array_ $options = [])

Returns the stashes that you currently have

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$stashes = $git->stash->lists();
```

##### Output Example

``` php
[
    0 => ['branch' => 'master', 'message' => '0e2f473 Fixes README.md'],
    1 => ['branch' => 'master', 'message' => 'ce1ddde Initial commit'],
]
```

#### $git->stash->show(_string_ $stash = null)

Show the changes recorded in the stash as a diff between the stashed state and its original parent

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
echo $git->stash->show('stash@{0}');
```

##### Output Example

```
 REAMDE.md |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
```

#### $git->stash->drop(_string_ $stash = null)

Remove a single stashed state from the stash list

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->drop('stash@{0}');
```

#### $git->stash->pop(_string_ $stash = null, _array_ $options = [])

Remove a single stashed state from the stash list and apply it on top of the current working tree state

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->pop('stash@{0}');
```

#### $git->stash->apply(_string_ $stash = null, _array_ $options = [])

Like pop, but do not remove the state from the stash list

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->apply('stash@{0}');
```

#### $git->stash->branch(_string_ $name, _string_ $stash = null)

Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created, applies the changes recorded in <stash> to the new working tree and index

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->branch('hotfix', 'stash@{0}');
```

#### $git->stash->clear()

Remove all the stashed states

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->clear();
```

#### $git->stash->create()

Create a stash (which is a regular commit object) and return its object name, without storing it anywhere in the ref namespace

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$commit = $git->stash->create();
```

##### Output Example

```
877316ea6f95c43b7ccc2c2a362eeedfa78b597d
```

* * * * *

### git status

#### $git->status(_array_ $options = [])

Returns the working tree status

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$status = $git->status();
```

##### Constants

- StatusCommand::UNMODIFIED            [=' '] unmodified
- StatusCommand::MODIFIED              [='M'] modified
- StatusCommand::ADDED                 [='A'] added
- StatusCommand::DELETED               [='D'] deleted
- StatusCommand::RENAMED               [='R'] renamed
- StatusCommand::COPIED                [='C'] copied
- StatusCommand::UPDATED_BUT_UNMERGED  [='U'] updated but unmerged
- StatusCommand::UNTRACKED             [='?'] untracked
- StatusCommand::IGNORED               [='!'] ignored

##### Output Example

``` php
[
    'branch' => 'master',
    'changes' => [
        ['file' => 'item1.txt', 'index' => 'A', 'work_tree' => 'M'],
        ['file' => 'item2.txt', 'index' => 'A', 'work_tree' => ' '],
        ['file' => 'item3.txt', 'index' => '?', 'work_tree' => '?'],
    ]
]
```

##### Options

- **ignored** (_boolean_) Show ignored files as well

* * * * *

### git tag

#### $git->tag()

Returns an array of tags

``` php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$tags = $git->tag();
```

##### Output Example

```
['v1.0.0', 'v1.0.1', 'v1.0.2']
```

#### $git->tag->create(_string_ $tag, _string_ $commit = null, _array_ $options = [])

Creates a tag object

``` php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->tag->create('v1.0.0');
```

##### Options

- **annotate** (_boolean_) Make an unsigned, annotated tag object
- **sign**     (_boolean_) Make a GPG-signed tag, using the default e-mail address’s key
- **force**    (_boolean_) Replace an existing tag with the given name (instead of failing)

#### $git->tag->delete(_string|array|\Traversable_ $tag)

Delete existing tags with the given names

#### $git->tag->verify(_string|array|\Traversable_ $tag)

Verify the gpg signature of the given tag names

* * * * *

### git ls-tree

#### $git->tree(_string_ $branch = master, _string_ $path = '')

Returns the contents of a tree object

``` php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$tree = $git->tree('master');
```

##### Output Example

``` php
[
    ['mode' => '100644', 'type' => 'blob', 'hash' => '1f100ce9855b66111d34b9807e47a73a9e7359f3', 'file' => '.gitignore', 'sort' => '2:.gitignore'],
    ['mode' => '100644', 'type' => 'blob', 'hash' => 'e0bfe494537037451b09c32636c8c2c9795c05c0', 'file' => '.travis.yml', 'sort' => '2:.travis.yml'],
    ['mode' => '040000', 'type' => 'tree', 'hash' => '8d5438e79f77cd72de80c49a413f4edde1f3e291', 'file' => 'bin', 'sort' => '1:.bin'],
]
```

License
-------

The MIT License

Author
------

Kazuyuki Hayashi (@kzykhys)