var express = require('express');
var Git = require("nodegit");
var fs = require('fs');
var router = express.Router();
var GITHUB_TOKEN = process.env.GITHUB_TOKEN;
var FILE_NAME = "index.htm";
var content;
var repo;
var head;
var oid;

router.post('/issues', function(req, res, next) {
  Git.Clone("https://" + GITHUB_TOKEN + ":x-oauth-basic@github.com/kewang/information-people", "./tmp", {
    checkoutBranch: "gh-pages"
  }).then(function(repoResult){
    repo = repoResult;

    console.log("getHeadCommit");

    return repo.getHeadCommit();
  }).then(function(headResult){
    head = headResult;
    console.log("getEntry");

    return head.getEntry(FILE_NAME);
  }).then(function(entry){
    console.log("getBlob");

    return entry.getBlob();
  }).then(function(blob){
    content = "DEF" + String(blob) + "ABC";

    fs.writeFileSync("./tmp/" + FILE_NAME, content);

    return repo.index();
  }).then(function(index){
    index.addByPath(FILE_NAME);
    index.write();

    return index.writeTree();
  }).then(function(oidResult){
    oid = oidResult;

    var author = Git.Signature.now("kewang", "cpckewang@gmail.com");

    return repo.createCommit("HEAD", author, author, "Add test", oid, [head]);
  }).then(function(commitId){
    console.log("New Commit: " + commitId);

    var remote = repo.getRemote("origin");

    // var remote = Git.Remote.create(repo, "origin", "https://" + GITHUB_TOKEN + ":x-oauth-basic@github.com/kewang/information-people");

    console.log("remote: " + remote);

    return remote.push(["refs/heads/master:refs/heads/master"]);
  }).done(function(){
    console.log("Push OK");

    return res.json(content);
  });
});

module.exports = router;

@@ -227,16 +227,86 @@
 var oid;
+%0Avar BRANCH_NAME = %22gh-pages%22;%0Avar REFS = %22refs/heads/%22 + BRANCH_NAME;
 %0A%0Arouter
@@ -475,26 +475,27 @@
 Branch: 
-%22gh-pages%22
+BRANCH_NAME
 %0A  %7D).th
@@ -1357,28 +1357,22 @@
 );%0A%0A    
-var remote =
+return
  repo.ge
@@ -1394,186 +1394,35 @@
 %22);%0A
-%0A
   
-  // var remote = Git.Remote.create(repo, %22origin%22, %22https://%22 + GITHUB_TOKEN + %22:x-oauth-basic@github.com/kewang/information-people%22);%0A%0A    console.log(%22remote: %22 + 
+%7D).then(function(
 remote)
-;%0A
+%7B
 %0A   
@@ -1446,45 +1446,25 @@
 sh(%5B
-%22refs/heads/master:refs/heads/master%22
+REFS + %22:%22 + REFS
 %5D);%0A

Test nodegit success