Server Git开发流程

一、协作流程参照下图

二、分支简介

master分支:永远处于稳定状态,这个分支代码可以随时用来部署。不允许在该分支直接提交代码。
develop分支:开发分支,如果要增加一个新的功能,请从master分支拉取出一个分支,分支名约定为develop/xxx

三、具体的操作流程

1、创建分支或者拉取远程仓库别人创建的分支

//创建分支并提交到远程仓库
git checkout -b develop/新分支名称 master //创建分支并切换到“develop/新分支名称”分支
git push -u origin develop/新分支名称 //第一次提交需要加-u,这样可以绑定本地和远程分支关系,之后push和pull不用再指定后面“origin develop/新分支名称”
  
//拉取远程仓库别人创建的分支
git fetch origin 
git branch -a //查看所有分支,包括本地和远程
git checkout -b develop/新分支 origin/develop/新分支 //“origin/develop/新分支”是远程仓库别人创建的分支

2、开发完新功能合并master,并测试,进行上线

//--no-ff会禁用Fast forward模式
git merge --no-ff master

3、上线完之后,需要将开发分支合并回master

//合并到master
git checkout master
git merge --no-ff develop/xxx

四、使用技巧

1、配置快捷命令

git config --global alias.st status  //git status 简化 git st
git config --global alias.co checkout //git checkout 简化 git co
git config --global alias.ci commit //git checkout 简化 git ci
git config --global alias.br branch //git checkout 简化 git br
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
原文地址:https://www.cnblogs.com/hifelix/p/6042408.html