title: Use R to push local repo to github on Windows
body: <p>I once asked a very <a href="https://stackoverflow.com/questions/14912161/repo-from-rstudio-to-github">similar question</a> and got a response that worked from the command line but am now wanting to use R to automate the process from Windows (Linux is much easier).  </p>
  
  <p>Here is what I'm trying to do:</p>
  
  <ol>
  <li>Create a local directory (or it exists already)</li>
  <li>Generate a new github repo in the cloud by the same name as local (<a href="https://stackoverflow.com/questions/15042418/send-to-github-via-curl-command-line-windows">based on this answer</a>)</li>
  <li>Add a .git to the local repo</li>
  <li>Make an initial commit</li>
  <li>Establish link between cloud repo and local repo</li>
  <li>Push the commit and the files in the local repo to github</li>
  </ol>
  
  <p>I believe <a href="https://dl.dropboxusercontent.com/u/61803503/Errors/github_push.txt" rel="nofollow noreferrer">based on the output</a> that I get all the way to step 5 before I fail (as the commit and files from the local directory never go to github in the cloud).  I know step 2 works because the empty repo is created <a href="https://github.com/trinker/foo5" rel="nofollow noreferrer">here</a>.  I don't know how to test step 5.  At the last step <code>shell(cmd6, intern = T)</code> RGui and RStudio result in an eternal death spiral.  The question is: <strong>How can I push the commit and local repo to the cloud.</strong>  </p>
  
  <p><strong>Here is my updated code (<em>the only thing that is user specific is username and password in third code chunk</em>):</strong></p>
  
  <pre><code>## Create Directory
  repo &lt;- "foo5"
  dir.create(repo)
  project.dir &lt;- file.path(getwd(), repo) 
  
  ## Throw a READ.ME in the directory
  cat("This is a test", file=file.path(project.dir, "READ.ME"))
  
  ## Github info (this will change per user)
  password &lt;-"pass" 
  github.user &lt;- "trinker"  
  
  ## Get git location
  test &lt;- c(file.exists("C:/Program Files (x86)/Git/bin/git.exe"),
      file.exists("C:/Program Files/Git/bin/git.exe"))
  gitpath &lt;- c("C:/Program Files (x86)/Git/bin/git.exe",
    "C:/Program Files/Git/bin/git.exe")[test][1]
  
  ## download curl and set up github api
  wincurl &lt;- "http://curl.askapache.com/download/curl-7.32.0-win64-ssl-sspi.zip"
  url &lt;- wincurl
  tmp &lt;- tempfile( fileext = ".zip" )
  download.file(url,tmp)
  unzip(tmp, exdir = tempdir())       
  shell(paste0(tempdir(), "/curl http://curl.haxx.se/ca/cacert.pem -o " , 
      tempdir() , "/curl-ca-bundle.crt"))
  json &lt;- paste0(" { \"name\":\"" , repo , "\" } ") #string we desire formatting
  json &lt;- shQuote(json , type = "cmd" )
  cmd1 &lt;- paste0( tempdir() ,"/curl -i -u \"" , github.user , ":" , password , 
      "\" https://api.github.com/user/repos -d " , json )
  
  shell(cmd1, intern = T)
  
  ## Change working directory
  wd &lt;- getwd()
  setwd(project.dir)
  
  ## set up the .git directory
  cmd2 &lt;- paste0(shQuote(gitpath), " init")
  shell(cmd2, intern = T)
  
  ## add all the contents of the directory for tracking
  cmd3 &lt;- paste0(shQuote(gitpath), " add .")  
  shell(cmd3, intern = T)       
  
  cmdStat &lt;- paste0(shQuote(gitpath), " status")  
  shell(cmdStat, intern = T)
  
  ## Set email (may not be needed)
  Trim &lt;- function (x) gsub("^\\s+|\\s+$", "", x) #remove trailing/leading white 
  
  x &lt;- file.path(path.expand("~"), ".gitconfig")
  if (file.exists(x)) {
      y &lt;- readLines(x)
      email &lt;- Trim(unlist(strsplit(y[grepl("email = ", y)], "email ="))[2])
  } else {
      z &lt;- file.path(Sys.getenv("HOME"), ".gitconfig")
      if (file.exists(z)) {
          email &lt;- Trim(unlist(strsplit(y[grepl("email = ", y)], "email ="))[2])
      } else {
          warning(paste("Set `email` in", x))
      }
  }
  cmdEM &lt;- paste0(shQuote(gitpath), sprintf(" config --global user.email %s", email))        
  system(cmdEM, intern = T)
  
  ## Initial commit
  cmd4 &lt;- paste0(shQuote(gitpath), ' commit -m "Initial commit"')  
  system(cmd4, intern = T) 
  
  ## establish connection between local and remote
  cmd5 &lt;- paste0(shQuote(gitpath), " remote add origin https://github.com/",
      github.user, "/", repo, ".git")  
  shell(cmd5, intern = T) 
  
  ## push local to remote 
  cmd6 &lt;- paste0(shQuote(gitpath), " push -u origin master")  
  shell(cmd6, intern = T) 
  
  setwd(wd)
  </code></pre>
  
  <p>I know the script is a bit longer but it's all necessary to recreate the problem and replicate the issue:</p>
  
  <p><strong>Note</strong> I updated the question in light of Simon's response as he was correct and got closer to the push.  The content of the original question can be found <a href="https://copy.com/SDmx8irgIEGpoXTP" rel="nofollow noreferrer">here</a>.</p>