GIT Pull Using Nodejs
I am sharing my code to take GIT pull through NodeJS. May be this small code can help someone.
// create config module
var config = {};
to_dir_client = "path to folder...";
client_git_repo = "Bitbucket URL... ";
// export config object as a node module
export default config;
/*-----------------------------------------------------------
--- install git repo js file
-----------------------------------------------------------*/
// include modules
import config, { to_dir_client, client_git_repo } from './config';
import gitP from 'simple-git/promise';
// install repo
const git_client = gitP(to_dir_client);
git_client.checkIsRepo()
.then(isRepo => !isRepo && initialiseClientRepo(git_client))
.then(() => git_client.pull('origin', 'master'));
// function to add origin
function initialiseClientRepo (git) {
return git.init()
.then(() => git.addRemote('origin', client_git_repo))
}