GitHub简介
github是目前世界上最大的代码存放网站和开源社区。我们可以利用github创建自己的代码仓库,同时访问追踪其他人的代码仓库,还可以多人协同完成工作项目。
使用方法总结
github有很多作用,对于常见的作用:
git add filename
git commit -m 'update'
git push
git pull
git add .
git commit -m 'update'
git push
具体使用教程
1. 下载安装git,R,Rstudio,并注册github账号
这些准备工作很简单,这里不做介绍。
2. 创建github资源库(repository)
打开https://github.com/new
输入资源库的名字(库的名字与本地的dir_name可以不同),添加描述(可选择),设置是公开还是私秘的(私密的需要付费),勾选创建readme文件(这里最好勾选,如果是空目录的话,本地同步github会出现错误),创建。
3.通过Rstudio关联本地文件和github
然后打开Tools,Globe Options,Git/SVN, 选择git安装路径,同时点击View public key, 复制;
然后打开github settings的 keys, 创建New SSH key, 将复制的key粘贴进去
4.本地文件夹与github关联
打开Tools的shell窗口,首先设置用户名和邮箱
git config --global user.email "renyunxiao16@big.ac.cn"
git config --global user.name "yunxiao"
添加本地文件或文件夹
git init
git remote add origin https:
git commit -m 'first commit'
git push origin master
若是已知仓库,添加更新文件
git pull
git add .
git commit -a -m "update"
git push origin master
常见错误及解决办法
git push origin master
To https:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/lassefolkersen/ren-folkersen-deconvolution.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git pull origin master
git push -u origin master -f
其他常见操作
删除仓库或文件夹
删除仓库从settings下删除,删除文件从命令行即可
git remote rm test
恢复历史版本
git reflog
10e2ff3 (HEAD -> master, origin/master) HEAD@{0}: reset: moving to 10e2
10e2ff3 (HEAD -> master, origin/master) HEAD@{1}: commit (initial): add folder
$ git reset --hard 10e2
HEAD is now at 10e2ff3 add folder
git 学习资源
廖雪峰git教程
|