Skip to content

Instantly share code, notes, and snippets.

@frontmesh
Last active December 17, 2015 06:48
Show Gist options
  • Save frontmesh/5567649 to your computer and use it in GitHub Desktop.
Save frontmesh/5567649 to your computer and use it in GitHub Desktop.
Git-merge as a bash script, requires nodejs for execution. Make this script executable chmod +x git-merge, than do a copy/move to /usr/bin "git-merge [branch]"
#!/usr/bin/node
var sys = require('sys')
, exec = require('child_process').exec
, current_branch
, target_branch = process.argv[2];
function puts (error, stdout, stderr){
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
if(error !== null) {
console.log('exec error: ' + error);
}
}
exec('git branch|grep "*"', function(err, stdout, stderr){
if(err == null){
current_branch = stdout.substring(2);
console.log(current_branch);
if( target_branch ){
//do a checkout of a target branch
exec('git checkout ' + target_branch, function(error,stdout, stderr){
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
if(error !== null) {
console.log('exec error: ' + error);
} else {
//do a pull origin of a terget branch
exec('git pull origin ' + target_branch, function(error, stdout,stderr){
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
// do a checkout of your previous branch
exec('git checkout ' + current_branch, function(error, stdout,stderr){
sys.puts(stdout);
//merge the target branch;
exec('git merge ' + target_branch, puts);
});
})
}
});
} else {
console.log("No target branch for merge defined");
}
} else {
console.log('exec error: ' + err);
}
});
@svetomirm
Copy link

Nice piece of code. Thanks frontmesh!

@svetomirm
Copy link

It does what it says it do ! Great job !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment