Skip to content

Instantly share code, notes, and snippets.

@balvinder294
Created August 7, 2019 11:33
Show Gist options
  • Save balvinder294/e9b8b84d5e80819d93b59d55257a91fe to your computer and use it in GitHub Desktop.
Save balvinder294/e9b8b84d5e80819d93b59d55257a91fe to your computer and use it in GitHub Desktop.
Push Repo online To Github via nodejs
// change current directory to repo directory in local
shellJs.cd('path/to/repo/folder');
// Repo name
const repo = 'dummy'; //Repo name
// User name and password of your GitHub
const userName = 'username';
const password = 'password';
// Set up GitHub url like this so no manual entry of user pass needed
const gitHubUrl = `https://${userName}:${password}@github.com/${userName}/${repo}`;
// add local git config like username and email
simpleGit.addConfig('user.email','balvinder294@gmail.com');
simpleGit.addConfig('user.name','Balvinder Singh');
// Add remore repo url as origin to repo
simpleGitPromise.addRemote('origin',gitHubUrl);
// Add all files for commit
simpleGitPromise.add('.')
.then(
(addSuccess) => {
console.log(addSuccess);
}, (failedAdd) => {
console.log('adding files failed');
});
// Commit files as Initial Commit
simpleGitPromise.commit('Intial commit by simplegit')
.then(
(successCommit) => {
console.log(successCommit);
}, (failed) => {
console.log('failed commmit');
});
// Finally push to online repository
simpleGitPromise.push('origin','master')
.then((success) => {
console.log('repo successfully pushed');
},(failed)=> {
console.log('repo push failed');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment