Skip to content

Instantly share code, notes, and snippets.

@zheng1
Last active August 29, 2015 14:02
Show Gist options
  • Save zheng1/5b121e2d9d0752512010 to your computer and use it in GitHub Desktop.
Save zheng1/5b121e2d9d0752512010 to your computer and use it in GitHub Desktop.
var exec = require('child_process').exec;
var child = exec('git remote -v',function(error, stdout, stderr) {
if (stderr) console.log('stderr: ' + stderr);
if (error) return console.log('exec error: ' + error);
var stdoutArr = stdout.split('\n');
var remoteLine = stdoutArr[0].split('\t');
var remoteName = remoteLine[0];
if (remoteLine[1].indexOf('git@') !== 0) return console.log('this project do not need change');
var remoteURL = remoteLine[1].replace('git@', 'http://').replace(/:/g, '/').replace('/', ':').split(' ')[0];
var cmd = ['git remote set-url', remoteName, remoteURL, '&& git config --global credential.helper store'].join(' ');
exec(cmd);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment