GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — nodegit/guides/repositories/initializing at master · codercatdev/nodegit

Expand file tree

/

initializing

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

initializing

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
README.md
README.md
 
 
index.js
index.js
 
 

README.md

Outline
layout full
menu_item guides
title Initializing
description How to initialize a repository

In order to run examples, you will need to Install NodeGit first.

Return to all guides


Initializing a Repository

This guide explains how to create a new repository.

View example source

Requiring NodeGit

In the guides directory, we like to keep our NodeGit relative to the project root.

var NodeGit = require("../../../");

However, in your project you will most likely be using the following command:

var NodeGit = require("nodegit");

Arguments to initialize a repo

There are 2 arguments to the init method, a path to initialize the repo in and whether or not to make a .git subfolder in that directory or use the passed in directory as the .git folder itself.

var pathToRepo = require("path").resolve("../my-git-projects/my-project");
var isBare = 0; // lets create a .git subfolder

Initialize the Repo

Now that we have our arguments we can call the init method on the NodeGit.Repository module to create the repo.

NodeGit.Repository.init(pathToRepo, isBare).then(function (repo) {
  // In this function we have a repo object that we can perform git operations
  // on.

  // Note that with a new repository many functions will fail until there is
  // an initial commit.
});
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.