I need a reliable way to clone a github repo and paste it into a local directory using node.js and any necessary npm packages.
This code is using the nodegit library and doesn't work to clone a github repo. it creates a single folder named .git and copies none of the files from the repo. I have tried several libraries most of which have extremely complicated code or don't work. This was working before but now isn't. (it goes on and off as it pleases). pls help, I need a reliable code that clones a github repo from url and pastes it into a local directory. Thank you.
var nodegit = require('nodegit'),
path = require('path');
var url = "https://github.com/atomicptr/dauntless-builder", //also tried https://github.com/atomicptr/dauntless-builder.git
local = "C:/data",
cloneOpts = {};
nodegit.Clone(url, local, cloneOpts).then(function (repo) {
console.log("cloning succesful!");
console.log("Cloned " + path.basename(url) + " to " + repo.workdir());
}).catch(function (err) {
console.log(err);
});
this code shows no errors, yet doesn't actually work to clone the repo.
You can use shelljs for this.
const shell = require('shelljs')
const path = 'absolute/path/to/folder'
shell.cd(path)
shell.exec('git clone https://github.com/atomicptr/dauntless-builder')
Assuming you have git installed on the machine you could simply run the clone command from node.
const path = require('path');
const{ execSync } = require('child_process');
execSync('git clone repolink', {
stdio: [0, 1, 2], // we need this so node will print the command output
cwd: path.resolve(__dirname, ''), // path to where you want to save the file
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With