企业团队使用Git协同开发的一般流程

简介:

流程大纲

一、代码编写

1.从主分支(master)上创建开发分支(dev)。 

git branch dev

2.切换到dev。 

git checkout dev

3.在dev上进行代码编写,并提交本地版本库。 
注:一定不能直接在marster分支上修改代码

git add ./src ./res
git commit -m "添加缓存模块"

这个时候有一些改变了没有提交的代码会变红色,在你 切换到master之前,应该暂存当前dev的开发一下到栈里。

git stash


二、合并代码

1.切换到master。 

git checkout master


2.从remote master拉取最新代码到local master。 

admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (dev)
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master)
$ git pull
Username for 'http://gitlab.urd.com': zengjinlong
Password for 'http://zengjinlong@gitlab.urd.com':
fatal: Authentication failed for 'http://gitlab.urd.com/kankan/kankananime.git/'


admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master)
$ git pull
Username for 'http://gitlab.urd.com': zengjinlong
Password for 'http://zengjinlong@gitlab.urd.com':
Already up-to-date.

admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master)
$


3.切换到dev。 

git checkout dev


4.rebase master 到 dev。 

git rebase master


5.如果有代码冲突,则解决。

三、提交代码

1.切换到master。 

git checkout master


2.将dev的代码合并(merge)到master。 

git merge dev


3.推送(push)local master 到 remote master。 

git push


4.看你心情,保留或者删除dev分支。

回到dev开发,要从stash中取出暂存的状态

git stash pop


总结流程如下:

git clone URL
(master branch now)
git branch dev
(new dev bransh to develop)
git checkout dev
(switch dev bransh now)
(.....coding ..add ... delete..modify...)
git add ./src ./res
(just add src and res in the local reposity)
git stash
(push the status into git stack,as some files modified but not add and committed)
git checkout master
git pull
(update the code from server .)
git checkout dev
git rebase master
(rebase from master.)
(solve the conflict code)
git checkout master
git merge dev
(merge the code from dev)
git push
(upload the new code to server)
git checkout dev
git stash pop
(ok, continue coding ,man )

如果不小心在master分支改动了代码怎么办?

git stash表示的是暂存从上一个commit到现在的改动,一旦你执行了该指令,当前分支会回退到上一次commit时候的状态。所以如果你master改动了。你可以如下处理

git status
(you will the modification is red)
git stash
(temporary store the modification into stack)
git status
(no red file now, as the branch rallback to the latest commit)
git pull
(update the code from the server)
(if you want to save the modification, you need still step on following steps)
git checkout dev
git rebase master
(update the code base on master)
git stash pop
(pop the stored code out)



以EclipseGit插件为例演示

  • 创建Dev分支CreateBranchDevCreateBranchDetail
  • 在marster分支上拉取最新代码PullToMarster
  • 在dev分支上rebase Marster分支代码RebaseFromMarsterToDevRebaseDetail
  • 在Marster分支上合并dev分支代码MergeFromDevToMasterMergeDetail
  • 提交marster分支到远程库PushToRemote
相关文章
|
7天前
|
测试技术 开发工具 数据库
《Git 简易速速上手小册》第4章:Git 与团队合作(2024 最新版)
《Git 简易速速上手小册》第4章:Git 与团队合作(2024 最新版)
26 1
|
3月前
|
开发工具 git 开发者
百度搜索:蓝易云【Git实际开发的流程】
以上是Git在实际开发中的一般流程。Git的分布式版本控制系统使得团队开发更加高效和灵活,并能有效管理项目的版本历史。
31 1
|
4月前
|
存储 开发工具 git
Git的正确使用姿势与最佳事件:团队协作开发和版本控制的最佳实践
Git 是目前最流行的分布式版本控制系统之一,它提供了强大而灵活的工具来管理项目的版本和协作开发。无论您是个人开发者还是团队成员,掌握 Git 的使用方法都是必不可少的。本文将引导您从 Git 的基础知识开始,逐步探索 Git 的进阶功能。
|
4月前
|
数据可视化 Go 开发工具
cggit 简化 Git 提交、合并、分支偏移小神器,提升开发、修BUG效率!
cggit 简化 Git 提交、合并、分支偏移小神器,提升开发、修BUG效率!
40 0
|
1月前
|
测试技术 开发工具 git
【git 实用指南】Git提交指南:如何制定团队友好的提交规则
【git 实用指南】Git提交指南:如何制定团队友好的提交规则
81 0
|
2月前
|
存储 Linux 开发工具
如何使用Git进行团队协作开发
【2月更文挑战第3天】Git是一款分布式版本控制系统,被广泛应用于软件开发、网站开发等领域。本文将介绍如何使用Git进行团队协作开发,包括Git的基本概念、常用命令以及如何避免冲突等内容。
|
2月前
|
Linux 开发工具 git
【开发专题_03】unable to access ‘https://github.com/deviantony/docker-elk.git/‘: Failed connect to github
【开发专题_03】unable to access ‘https://github.com/deviantony/docker-elk.git/‘: Failed connect to github
|
2月前
|
存储 开发工具 git
Git工作流程:如何在团队中协作?
Git工作流程:如何在团队中协作?
|
3月前
|
存储 缓存 开发工具
Git 拉取合并代码流程和多人协同开发的问题解决方法
Git 拉取合并代码流程和多人协同开发的问题解决方法
66 0
|
3月前
|
网络安全 开发工具 git
Git在windows下上传文件至github流程
Git在windows下上传文件至github流程
22 0