美文网首页
GitHub学习笔记

GitHub学习笔记

作者: 浅墨如痕 | 来源:发表于2016-08-02 08:59 被阅读50次

GitHub workflow

Step1 源仓库的构建

该步骤由项目负责人操作,即新建一个repo

Step2 开发者fork源仓库

访问源仓库URL,点击fork

Step3 clone开发者仓库

cd到要存放本地repo的文件夹下

git clone https://github.com/Username/DemoRepo.git

Step4 构建功能branch进行开发

#切换到develop branch
git chekcout develop

#创建并切换到一个功能性branch
git checkout -b feature-function1

#进行开发

#提交更改
git add .
git commit -m 'Some description'

#回到develop branch
git checkout develop

#将做好的功能merge到develop中
git merge --no-ff feature-function1

#删除功能性branch
git branch -d feature-function1

#将本地的develop push到remote repo的develop branch中
git push origin develop

Step5 发起pull request申请

回到github网页,点击pull request发起申请

Step6 项目负责人测试、合并

该步骤由项目负责人进行操作

Git branch说明及命名格式

1.永久性branch

*master branch:主分支

*develop branch:开发分支

2.临时性branch

*feature branch:功能分支

*release branch:预发布分支

*hotfix branch:bug修复分支

命名格式:feature-*,*为功能名称

GitHub协同开发及冲突处理

保持与源仓库同步更新

1.查看是否添加了源仓库的远程源(首次操作)

git remote -v

2.如果此时只看到自己的两个源

origin  https://github.com/Username/DemoRepo.git (fetch)
origin  https://github.com/Username/DemoRepo.git (push)

此时则需要源仓库的远程源

git remote add upstream https://github.com/OriginUser/DemoRepo,git

然后再查看

git remote -v

则可以看到四个源(两个upstream)

3.与源仓库合并(同步源仓库的更新,此时更新的是自己本地的repo,自己的远程repo并没有更新,需要进行push操作),如果是团队开发则合并develop branch, 如果是fork别人的repo则一般应为master branch

git fetch upstream
git merge upstream/develop

冲突处理

当自己与其他人对同一文件进行操作时可能发生冲突,此时需要进行冲突处理

先commit自己的修改

git add .
git commit -m 'Some description'

然后pull自己远程repo的数据

git pull origin develop

如果提示conflict,则需要对有冲突的文件进行处理

<<<<<<< HEAD
/* 自己本地的内容 */
=======
/* 远程repo的内容 */
>>>>>>>

确定要保留的内容后将标记行删掉<<<<<<<,=======,>>>>>>>

再将修改后的文件提交一次(假设为index.html)

git add index.html
git commit -m 'Some description'

最后push

git push origin develop

此时若已开发完一个完整的功能就可以去pull request了

ps:因为开发需要才学习了git,如有不对的地方欢迎指正

相关文章

网友评论

      本文标题:GitHub学习笔记

      本文链接:https://www.haomeiwen.com/subject/pjsfsttx.html