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,如有不對的地方歡迎指正