@@ -5,6 +5,59 @@ title: Initializing
55description : How to initialize a repository
66---
77
8+ ** In order to run examples, you will need to [ Install NodeGit] ( ../../install/basics )
9+ first.**
10+
811[ Return to repository guides] ( ../ )
912
1013* * *
14+
15+ Initializing a Repository
16+ -------------------------
17+
18+ This guide explains how to create a new repository.
19+
20+ [ View example source] ( index.js )
21+
22+ ### Requiring NodeGit
23+
24+ In the guides directory, we like to keep our NodeGit relative to the project
25+ root.
26+
27+ ``` javascript
28+ var NodeGit = require (" ../../../" );
29+ ```
30+
31+ However, in your project you will most likely be using the following command:
32+
33+ ``` javascript
34+ var NodeGit = require (" nodegit" );
35+ ```
36+
37+ ### Arguments to initialize a repo
38+
39+ There are 2 arguments to the ` init ` method, a path to initialize the repo in
40+ and whether or not to make a ` .git ` subfolder in that directory or use the
41+ passed in directory as the ` .git ` folder itself.
42+
43+
44+ ``` javascript
45+ var pathToRepo = require (" path" ).resolve (" ../my-git-projects/my-project" );
46+ var isBare = 0 ; // lets create a .git subfolder
47+ ```
48+
49+
50+ ### Initialize the Repo
51+
52+ Now that we have our arguments we can call the ` init ` method on the
53+ ` NodeGit.Repository ` module to create the repo.
54+
55+ ``` javascript
56+ NodeGit .Repository .init (pathToRepo, isBare).then (function (repo ) {
57+ // In this function we have a repo object that we can perform git operations
58+ // on.
59+
60+ // Note that with a new repository many functions will fail until there is
61+ // an initial commit.
62+ });
63+ ```
0 commit comments