[转]Git branching and tagging best practices
Git branching and tagging best practices
I am currently learning to use Git by reading Pro Git. Right now I'm learning about branching and tags. My question is when should I use a branch and when should I use a tag?
For example, say I create a branch for version 1.1 of a project. When I finish and release this version, should I leave the branch to mark the release version? Or should I add a tag? If I add a tag, should I delete the version branch (assuming that it is merged into master or some other branch)?
In short: Best practice is branch out, merge often and keep always in sync.
There are pretty clear conventions about keeping your code in a separate branches from master branch:
- You are about to make an implementation of major or disruptive change
- You are about to make some changes that might not be used
- You want to experiment on something that you are not sure it will work
- When you are told to branch out, others might have something they need to do in master
Rule of thumb is after branching out, you should keep in sync with the master branch. Because eventually you need to merge it back to master. In order to avoid a huge complicated mess of conflicts when merging back, you should commit often, merge often.
Good practices to follow
A successful Git branching model by Vincent Driessen has good suggestions. If this branching model appeals to you consider the flow extension to git. Others have commented about flow.
Tagging practices
As you already know, Git gives you commit identifiers like 1.0-2-g1ab3183 but those are not tags! Tagging is done with git tag, and the tags that are created using git tag are the base for the commit identifiers git describe creates. In another words, in Git you don't tag branches. You are tagging commits. It is correct to say that tag is just an annotated pointer to a commit.
Lets look at practical example that demonstrated it,
/-- [v1.0]
v
---.---.---.---S---.---A <-- master
\
\-.---B <-- test
Let's commit 'S' be commit pointed by tag 'v1.0'. This commit is both on branch 'master' and on branch 'test'. If you run "git describe" on top of commit 'A' (top of 'master' branch) you would get something like v1.0-2-g9c116e9. If you run "git describe" on top of commit 'A' ( aka the 'test' branch) you would get something like v1.0-2-g3f55e41 , that is the case with default git-describe configuration. Note that this result is slightly different. v1.0-2-g9c116e9 means that we are at commit with sortened SHA-1 id of 9c116e9, 2 commits after tag v1.0. There is no tag v1.0-2!
If you want your tag to appear only on branch 'master', you can create new commit (e.g. only update default / fallback version information in GIT-VERSION-FILE) after branching point of 'test' branch. If you tag commits on 'test' branch with e.g. 'v1.0.3` it would be visible only from 'test'.
References
I have found many, many, useful blogs and posts to learn from. However, the ones that are professionally illustrated are rare ones. Thus, I would like to recommend a post - A successful Git branching model by @nvie. I have borrowed his illustration :)

- 21.0-2-g1ab3183 is an identifier constructed by git describe from information available from git, but calling it a git identifier is a little too much. Git identifies by SHA hash; tags and branches are human constructs that git helpfully keeps track of. As such, make a tag when you think some human will one day wish to find a convenient bookmark to a commit. – mabraham Apr 21 '14 at 23:52
[转]Git branching and tagging best practices的更多相关文章
- Using git-flow to automate your git branching workflow
Using git-flow to automate your git branching workflow Vincent Driessen’s branching model is a git b ...
- Illustration of Git branching and merge
网上看到的描述Git工作流程的图片,有些出处忘了保存,仅供学习. 1. One Git Branching Model 出处: http://nvie.com/posts/a-successful-g ...
- 【原创】Git 分支的合并【Learn Git Branching】
merge git merge是我们要学习的合并工作的第一个方法.合并产生一个特殊的提交记录,它包含两个唯一父提交.有两个父提交的提交记录本质上是:“我想把这两个父提交本身及它们的父提交集 ...
- GIT BRANCHING
GIT BRANCHING generalizations Let's take a moment to review the main concepts and commands from the ...
- A successful Git branching model——经典篇
A successful Git branching model In this post I present the development model that I’ve introduced f ...
- git 那些事儿 —— 基于 Learn Git Branching
前言 推荐一个 git 图形化教学网站:Learn Git Branching,这个网站有一个沙盒可以直接在上面模拟 git 的各种操作,操作效果使用图形的方式展示,非常直观.本文可以看作是它的文字版 ...
- (数据科学学习手札141)利用Learn Git Branching轻松学习git常用操作
1 简介 大家好我是费老师,Git作为世界上最流行的版本控制系统,可以说是每一位与程序打交道的朋友最值得学习的软件之一.除了管理自己的项目,如果你对参与开源项目感兴趣,那么Git更是联结Github. ...
- [转]实际项目中如何使用Git做分支管理 (A successful Git branching model)
来自 https://nvie.com/posts/a-successful-git-branching-model/ In this post I present the development m ...
- [转载] A successful Git branching model/GIT分支管理是一门艺术
转载自:http://www.cnblogs.com/baiyw/p/3303125.html 英文原文:http://www.nvie.com/posts/a-successful-git-bran ...
随机推荐
- AC日记——[HNOI2008]GT考试 bzoj 1009
1009 思路: KMP上走DP(矩阵加速): DP[i][j]表示当前在第i位,同是匹配到不吉利串的第j位的方案数: 代码: #include <bits/stdc++.h> using ...
- 部署openstack(N)版本-本地yum源(1)
部署本地openstack yum源,原因主要是我想安装老版本,N版(newton),部署本地yum源,安装速度可以更快. 1. 使用apache提供yum服务 yum install -y http ...
- win 10 下面安装 mysql-8.0.12-winx64 的过程
win 10 下面安装 mysql-8.0.12-winx64 的过程 1.官网下载 mysql 2.解压到你要安装的目录 3.在mysql目录D:\Programming\mysql-8.0.12- ...
- LOJ #6277. 数列分块入门 1-分块(区间加法、单点查询)
#6277. 数列分块入门 1 内存限制:256 MiB时间限制:100 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2 题目描述 给出 ...
- Xamarin提示安装包错误解决办法
Xamarin提示安装包错误解决办法大学霸 Xamarin提示安装包错误,错误信息类似于:Please install package:'Xamarin.Android.Support.v7.Medi ...
- SqlHelper——只因为在人群中多看了你一眼
对SQLHelper,还是有一点陌生的,但是大多数人都在使用,我就有一种想了解并使用的意愿,于是查了很多资料,发现一片不错的博客,放在下面,作为自己或读者使用的材料. 一.SqlHelper 出场 不 ...
- [BZOJ5248][九省联考2018]一双木棋(连通性DP,对抗搜索)
5248: [2018多省省队联测]一双木棋 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 43 Solved: 34[Submit][Status ...
- [Codeforces-div.1 68D] Half-decay tree
[Codeforces-div.1 68D] Half-decay tree 试题分析 增加显然是\(log\)的. 由于某一些叶子结点的答案是一样的,所以我们可以考虑一次性求解. 容易想到一个非常优 ...
- 【枚举】【高斯消元】Gym - 101412D - Find the Outlier
给你一个未知的d次多项式在0,1,...,d+2处的取值,其中有且只有一个是错的,问你哪个是错的. 枚举哪个是错的,再在剩下的d+2个中取d+1个高斯消元,解出多项式系数,然后代一下最后剩下的那个数看 ...
- matlab2016b ubuntu命令行安装 + matconvnet的安装
0. 下载安装包 下载的文件有Matlab 2016b Linux64 Crack.rar,R2016b_glnxa64_dvd2.iso,R2016b_glnxa64_dvd1.iso. 1. 拷贝 ...
