代码版本控制是作为程序员,必须要考虑的问题,针对Rstudio可以利用Github进行版本控,下面对整个操作过程进行说明:
设定目录
在windows系统下,选择Tools --> Global Options,然后选择Git/SVN,选择Git executable,所以安装前提是你要有先安装Git,如下图所示

然后
Create RSA Key



打开Tools,选择shell,输入命令:
git config --global user.email "youremail@gmail.com
git config --global user.name "yourname"
ssh -T git@github.com
使用GitHub上的名字

新建一个一个工程
新建一个工程,选择New Directory

然后勾选Create a git repository

这个时候Rstudio会出现git栏,提交到本地,只需要在git栏下面点击commit,即可提交至本地

可以将代码保存至GitHub上,并且创建分支,在GitHub上创建一个New respository,命名为test

打开Rstudio中的Shell窗口,输入git命令
git remote add origin https://github.com/chengfeifan/test.git
git config remote.origin.url git@github.com:chengfeifan/test.git
git pull origin master
git push origin master
将origin重新定向
git remote set-url origin https://github.com/chengfeifan/test.git
在本地新建一个GitHub上已经存在的项目
首先在Rstudio上新建一个project,选择version control,然后选Clone Git Respository,将GitHub上repository的url加入到选项中

然后在shell窗口输入
git config remote.origin.url git@github.com:ewenharrison/test.git
git中设置上游
在git的时候,我们会建立许多有特性的分支,建立分支的时候,如何使得远端也出现分支,需要用到下面的命令:
git push --set-upstream origin master