0

I'm wanting to clone a git repository using node.js command prompt. What are the commands I need to use to create a project area and then clone the repo to it?

3
  • 1
    Is this just a normal command prompt? git clone <repo url> doesn't work? Commented Jul 26, 2018 at 17:44
  • Do you mean using the Nodejs REPL? Or do you mean you want to write a Nodejs script to do that? If you do mean the REPL, why? Commented Jul 27, 2018 at 0:08
  • Does this answer your question? How to clone github repo using node.js Commented Jun 18, 2020 at 21:45

2 Answers 2

0

Well, You can use shelljs or nodegit package. Let me describe a way to use shelljs.

const shell = require('shelljs')
const path = process.cwd
shell.cd(path)
shell.exec('git clone https://github.com/<github-name>/<git-repos>')

Then it is a way to use nodegit.

const clone = require("nodegit").Clone.clone

const path = process.cwd

clone("https://github.com/<github-name>/<git-repos>", path)
  .then(function () {
    // Repo is available in `path`
  })
Sign up to request clarification or add additional context in comments.

Comments

0

Adding onto @Venus713's solution, you can use node-cmd to clone repositories.

const cmd = require('node-cmd');
const clone = cmd.runSync('git clone https://github.com/<username>/<repo>');

// runSync returns the output of the command, which is console logged below.

console.log(clone);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.