Use R to push local repo to github on Windows Use R to push local repo to github on Windows r r

Use R to push local repo to github on Windows


If are using https address, then make sure that:

  • the environment variable %HOME% is defined
  • a _netrc file exists in it with the right credential to push back to your repo

That file shoud contains:

machine github.comlogin usernamepassword xxxxprotocol https

That works even if you have activated the recent two-factor authentication on GitHub.

Then your push won't time out:

cmd6 <- paste0(shQuote(gitpath), " push -u origin master")  shell(cmd6, intern = T) 

This is easier than setting public/private ssh keys.


As the OP Tyler Rinker commented, setting %HOME% is illustrated in my other answer "Git - How to use .netrc file on windows to save user and password".
This is normally done by git-cmd.bat:

if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%@if not exist "%HOME%" @set HOME=%USERPROFILE%

But you can do it manually as well.


The problem simply seems to be mixing up ssh and https protocols.

Note the URLs should be:

#  https:"https://github.com/<username>/<myrepo>.git"#  ssh:"git@github.com:<username>/<repo>.git"

You have:

cmd5 <- paste0(shQuote(gitpath), " remote add origin https://github.com:",github.user, "/", repo, ".git") cat( cmd5 )"... remote add origin https://github.com:trinker/foo2.git"

Just change cmd5 to

# Note the forward slash at EOL in place of the coloncmd5 <- paste0(shQuote(gitpath), " remote add origin https://github.com/",github.user, "/", repo, ".git")"... remote add origin https://github.com/trinker/foo2.git"

It also couldn't hurt to run this immediately after git add .:

cmdStat <- paste0(shQuote(gitpath), " status")  shell(cmdStat, intern = T)