Created
August 7, 2019 11:33
-
-
Save balvinder294/e9b8b84d5e80819d93b59d55257a91fe to your computer and use it in GitHub Desktop.
Push Repo online To Github via nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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','[email protected]'); | |
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