Clone git repository with nodegit.
$ npm install --save nodegit-clone
import clone from 'nodegit-clone';
clone('https://github.com/owner/repo')
.then(repo => {
// Access any repository methods here.
console.log(repo.path());
});
// path/to/repo/.git
Returns a Promise, that resolves to instance of Repository.
Type: string
The URL to the repository.
Note: the following protocols are supported: http
, https
, git
and ssh
.
clone('http://github.com/owner/repo');
clone('https://github.com/owner/repo');
clone('git://github.com/owner/repo.git');
clone('git@github.com:owner/repo.git');
Type: string
The Local path to store repository.
Note: if localPath
is not specified then repository will be cloned to directory with repository name.
Type: string
The GitHub personal OAuth token.
Type: object
The object with paths to ssh keys and passphrase.
Before you can clone a repository, you'll need a GitHub OAuth application token. You can find more information on generating one here: Creating an access token for command-line use.
In this example we're going to clone one of our private test repositories from GitHub. This must be an https protocol URL for the clone to work.
// Keep this value a secret. If you accidentally commit
// this key to a public GitHub repository they will immediately revoke it.
const GITHUB_TOKEN = '<GH_TOKEN>';
clone({
url: 'https://github.com/owner/private',
ghToken: GITHUB_TOKEN
});
Before you can clone a repository, you'll need SSH keys. You can find more information on generating them here: Generating an SSH key.
In this example we're going to clone one of our private test repositories. This must be an ssh protocol URL for the clone to work.
clone({
url: 'git@github.com:owner/private.git',
ssh: {
publicKey: '/path/to/public-key',
privateKey: '/path/to/private-key'
}
});
For encrypted keys you should specify the passphrase
option:
clone({
url: 'git@github.com:owner/private.git',
ssh: {
publicKey: '/path/to/public-key',
privateKey: '/path/to/private-key',
passphrase: 'password'
}
});
MIT © Andrew Abramov