Skip to content

Clone a Github repository programmatically. Hybrid, Async and Promise API

License

Notifications You must be signed in to change notification settings

tunnckoCore/gitclone

Repository files navigation

Powerful and flexible programmatic interface for the git clone command, using gitclone-defaults and cross-spawn

code climate standard code style travis build status coverage status dependency status

Install

Install with npm

$ npm i gitclone --save

Usage

For more use-cases see the tests

const gitclone = require('gitclone')

API

Clones github repository, optionally pass destination folder. By defaults uses HTTPS to clone the repository. If you want SSH clone you should pass second, third or fourth argument boolean true, or object {ssh: true}. Pattern can be user/repo#branch as first argument. Or first argument user, second argument repo, third branch, fourth ssh.

Hint: All arguments are super flexible and they are handled absolutely directly with gitclone-defaults, so read its API docs. In addition, you also can pass callback as last argument, otherwise it will return Spawn stream.

Params

  • [callback] {Function}: optional, if not given, returns a stream
  • returns {Stream}: if not callback given as last argument - a Spawn stream

Example

const gitclone = require('gitclone')

// clones with SSH
gitclone('node-minibase/minibase', true)

// clone with HTTPS
gitclone('node-minibase/minibase', (err) => {
  if (err) return console.error(err)
})

// clone `dev` branch from `verbose/verb` repo
gitclone('verbose/verb#dev', console.log)

// clone `jonschlinkert/nanomatch` with SSH
gitclone('jonchlinkert', 'nanomatch', true)

// clone to different destination folder
gitclone('hybridables/always-done', { dest: 'foobar' })

// clone SSH + dest + branch
gitclone('verbose/verb', { dest: 'verb0.9.0', branch: 'dev', ssh: true })

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github