前面我记录了如何上传自己的项目到个人github账户上,当团队协作的时候,该如何运用git来进行版本控制呢?
1. 在项目的发起者或者Leader上传自己的代码到github上
([不清楚怎么上传自己的代码到github上的请点击这个链接]http://blog.youkuaiyun.com/gpwner/article/details/52829187)
这次我以Gpwner上的recyclerview这个项目来举例
2.点击项目的setting->Collaborators,输入团队成员的Github账户
然后就是坐等团队成员同意,这里假设Gpwner是项目的Leader,DiKeYuTa是成员。
3.在团队成员的PC上登录其账户,在这里是登录DiKeYuTa绑定的邮箱
可以看到DiKeYuTa绑定的邮箱已经收到了来自Gpwner的邀请了,点击
View invitation,然后会跳转到以下界面
点击accept invitation就可以了
4.现在Leader登录自己的账号就可以看到,团队成员已经成功添加到该项目的协作人员了
5.DiKeYuTa在自己的PC上clone下来该项目
我使用的是Git([Git安装教程,点击进入]http://blog.youkuaiyun.com/gpwner/article/details/52829187)
************************************************************************
如果没有配置好SSH key的,先配置以下,步骤如下:
- 在PC任意地方右键,选择
git bash here
然后输入:
ssh-keygen -t rsa -C "youremail@example.com"
//youremail@example.com是你的在github注册时候使用的时候的邮箱
然后一路回车,知道看到提示所创建的SSHkey路径,就说明你的SSH已经创建成功了
我SSHkey是在:C:\Users\Gpwner.ssh
进入该目录打开id_rsa.pub,打不开的选择打开方式为记事本 复制好里面的内容
然后在https://github.com
登录DiKeYuTa账号,进入个人账号下的setting->SSH and GPG KEY->New SSH KEY,输入标题和刚才复制好的ssh key,最好点击add SSH key
回到git bash
输入以下指令验证是否配置成功:
ssh -T git@github.com
如下图说明你的ssh已经配置成功了
************************************************************************
进入Leader的项目下复制好git远程地址。
在PC 的任意位置鼠标右键,选择git bash here
然后输入git clone git@github.com:Gpwner/Recyclerview.git
,静等clone完毕就好了
6.经过以上步骤,所有的准备工作已经完成了接下来就是更新你的代码到github上的远程仓库了,这里以我在clone下来的项目里面新添加了一个txt文件举例,
我在clone下项目的目录下,新建了一个2016年11月12日130728.txt文件
,然后回到git bash 中
每次提交新的代码,都要先同步远程仓库,看看有没有其他人有更新,否则自己的代码将无法提交上去
输入:
git pull
git add .
git commit -m "bbb"
git push
如果你不同步直接提交话有可能会报以下错误:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:Gpwner/Recyclerview.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.
回到Leader的账号,可以看到DiKeYuTa刚才提交的东西已经同步到了该远程仓库