Wednesday, December 14, 2016

DNSPod各个套餐的DNS地址-DNSPod 技术支持-DNSPod-免费智能DNS解析服务商-电信_网通_教育网,智能DNS

DNSPod各个套餐的DNS地址-DNSPod 技术支持-DNSPod-免费智能DNS解析服务商-电信_网通_教育网,智能DNS

DNSPod各个套餐的DNS地址
每种域名套餐对应的DNS地址是不同的!

免费DNS地址:f1g1ns1.dnspod.net/f1g1ns2.dnspod.net (对应 10 台服务器);
豪华DNS地址:ns1.dnsv2.com/ns2.dnsv2.com (对应 12 台服务器);
企业I DNS地址:ns1.dnsv3.com/ns2.dnsv3.com (对应 14 台服务器);
企业II DNS地址:ns1.dnsv4.com/ns2.dnsv4.com (对应 18 台服务器);
企业III DNS地址:ns1.dnsv5.com/ns2.dnsv5.com (对应 22 台服务器);
个人专业版DNS地址:ns3.dnsv2.com/ns4.dnsv2.com (对应 12 台服务器);
企业创业版DNS地址:ns3.dnsv3.com/ns4.dnsv3.com (对应 14 台服务器);
企业标准版 DNS地址:ns3.dnsv4.com/ns4.dnsv4.com (对应 18 台服务器);
企业旗舰版 DNS地址:ns3.dnsv5.com/ns4.dnsv5.com (对应 22 台服务器)。

2. 当前域名所对应的DNS地址,会在进入管理域名记录面板后,显示在下图位置:

Anomaly - MySQL Full-text Searches and SQLAlchemy; the Present and a Proposed Future

Anomaly - MySQL Full-text Searches and SQLAlchemy; the Present and a Proposed Future
MySQL Full-text Searches and SQLAlchemy; the Present and a Proposed Future

Addendum: Since the publication of this article we discovered Meng Zhuo's MySQL full-text add-on for SQLAlchemy and have decided to side with this existing effort over rolling our own solution.

MySQL supports an array of full-text search features recommended for performing advanced textual queries on fields of CHAR, VARCHAR and TEXT types. For a variety of great reasons Python is our language of choice and there's no better Pythonic interface to a relational database than SQLAlchemy.

SQLAlchemy is feature-packed and rock-solid. Unfortunately, it does not completely support all of what MySQL has to offer in the way of full-text searches.

The following article provides a brief introduction to full-text searching in MySQL, how—and to what extent—you can use it in SQLAlchemy 1.0.13 as well as our proposal for feature-complete full-text searching in SQLAlchemy and working with the core team to merge it back into the core code base.

Working with Full-text Indexes

Full-text indexes are created on one or a group of fields. The exact same set of fields must be used in MATCH and AGAINST syntax to perform full-text queries.

Indexes can be created as part of the initial table definition:

CREATE TABLE customer (
customer_id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
name VARCHAR(200),
physical_address_street TEXT(),
FULLTEXT name_index (name)
) ENGINE=InnoDB;
Or on an existing table:

CREATE FULLTEXT INDEX `name_index` ON customer(name);

/* or across multiple fields */

CREATE FULLTEXT INDEX `fulltext_index` ON customer(name, physical_address_street);
Queries performed using MATCH and AGAINST are able to make use of the full-text index. They can be run in three different modes:

Natural Language
Natural Language with Query Expansion
Boolean Mode
Note: The exact same fields used to create the full-text index must appear when running full-text searches.

MySQL's documentation covers querying in great detail. A basic BOOLEAN mode query would look as follows:

SELECT customer_id FROM customer WHERE MATCH(name) AGAINST('anomaly+ soft*' IN BOOLEAN MODE);

/* or across multiple fields */

SELECT customer_id FROM customer WHERE MATCH(name, physical_address_street)
AGAINST('anomaly+ soft*' IN BOOLEAN MODE);
Full-text Searching via SQLAlchemy

At present SQLAlchemy (as at version 1.0.13) has implemented fairly basic support for full-text searching. The query interface is limited to single fields and queries are preset to run in BOOLEAN mode.

customers = session.query(Customer).filter(Customer.name.match("anomaly")).all()
Running queries against multiple fields or other modes is only possible by rolling your own ClauseElement. There's an extensive thread on StackOverflow where Mike Bayer, the author of SQLAlchemy, has outlined a detailed solution.

Note: Using BOOLEAN mode operators crash SQLAlchemy. This would most likely be caused by the match function failing to compile the operators.

There's also no support for creating full-text indexes via the declarative_base. The best option is to hook onto the after_create event and create the index via the DDL.

event.listen(
Customer.__table__,
"after_create",
DDL("CREATE FULLTEXT INDEX `name` ON %(table)s(name)"))
Proposed Future

While investigating full-text support in SQLAlchemy, I had a brief discussion on the mailing list. As a result we've decided to take on the job of completely implementing MySQL full-text support in SQLAlchemy. We plan to support:

Creation of full-text indexes via the declarative_base
Multiple fields across multiple indexes
Querying multiple fields in BOOLEAN, NATURAL LANGUAGE and NATURAL LANGUAGE mode with QUERY EXPANSION
You can follow the development on our forked repository on Github.

databasepython

Monday, November 28, 2016

导致TCP协议联通性的两类问题汇总_百度文库

导致TCP协议联通性的两类问题汇总_百度文库
导致TCP联通性的两类问题汇总 手机无线网络环境比PC网络环境更复杂,因此也带来了一些特殊的网络问题。这些网络问题并非手机无线网独有,但是在手机无线网络中,由于有无线运营商这个环节,这个环节对互联网运营商是个黑盒,他们运维的一些特殊配置,更可能导致无线网络上的问题。这里主要汇总两类问题。 1:tcp连接无法正常建立 2:大数据传输不正常 这两类问题都不是普遍存在的,可能只存在某个运营商网络,或者某个省份的运营商。 首先来分析第一个问题。 Tcp连接无法建立,最直接的表现是app与server之间的tcp连接不能正常完成,导致用户无法正常连接到server上。这类问题处理起来的确棘手。涉及到的情况比较复杂,比如也许是用户当时的无线信号不稳定,也许是用户连接的wifi掉线了,也许某个运营商与server之间的网络就不通,等等类似问题。这类问题都有共通的几个特性:1,非大面积发生;2,比较难重现;3,用户现场比较难获取;4,用户配合定位问题难度搞;5,用户tcpdump抓包困难。 手机Qzone在运营过程中也遇到了以上问题,像信号不稳定,wifi不通这类问题比较好解决。联系用户,核实情况一般都可以解决。其中有一个隐藏比较深,是由于server内核参数设置不当引起的问题。无线环境下,有很大一部分原因是这个问题导致的。 做互联网server开发,为了支持高并发,server一般都会打开tcp_tw_reuse,tcp_tw_recycle。这两个选项都可以控制tcp快速回收。还有另一个设置 tcp_timestamp。这个设置往往被忽略了。如果tcp_tw_recycle,tcp_timestamp同时被设置,可能就会导致connect连接失败的问题。这里正确做法是关闭 tcp_timestamp。导致这个问题的原因是:某些运营商通过NAT方式组网,如果NAT网络中有台设备的时间戳有问题,就会导致其他机器都不能正常的connect上我们的server了。 现在分析下第二个问题。 第二个问题一般出现在app与server之间传输传输大数据,导致出现丢失数据问题。此类问题一般都是由MTU引起。这里特指PMTU,tcp传输路径上的MTU。因为两端的MTU在tcp三次握手的过程中已经协商好了,PMTU确无法协商。IP包头中有个DF标志,默认情况下是1,标识不允许IP包分片。如果有一个IP包在传输过程中经过一个路由器,这个路由器的MTU设置小于此IP包,此时候由于DF为1,路由器不做IP分片,而是直接丢弃此IP包,并返回一个ICMP报文。(现实中很多路由器设置了不返回ICMP报文,而是直接丢弃IP包)发送端无法感知IP是因为MTU问题被丢弃,还是其他原因未到达对端,对于发送端来说,就是这个IP包丢包,于是触发了tcp的超时重传。但是由于这个问题是由于路由器MTU导致的,重传也解决不了问题。这里解决问题有几个方法: 1:更改server的mtu,改到一个比较小的值。这个方案可行,但是会影响这台server上的所有网络数据的mtu。一般建议改到1400左右,太小可能会引起更多ip碎片。 2:程序中设置DF为0,允许路由器对IP包做分片。 关闭df的方法: int val = IP_PMTUDISC_DONT;

int ret = setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)); 打开df的方法: int val = IP_PMTUDISC_DO; int ret = setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)); 3:可以通过程序设置mss,间接控制每个IP包大小。好处是不用更改server的mtu,只影响本程序。用setsockopt, SOL_TCP, TCP_MAXSEG设置。 以上方法主要解决了下行不通,有时候app到server也遇到数据太大的问题。 在这方面,Qzone在实现的时候,在客户端预埋了一个逻辑,如果客户端在上行大数据不通的时候,可以在客户端设置mss大小。具体设置多大,可以通过配置来控制。

Thursday, November 3, 2016

DNS�NO�GLUE_flyfish_carol_新浪博客

DNS�NO�GLUE_flyfish_carol_新浪博客





DNS NO GLUE

 (2006-12-11 15:22:31)

DNS NO GLUE

Author: Hagen.GoO  转载请注明作者出处
MSN contact: wantm009@hotmail.com
Keyword: DNS Report,NameServer,NS RRs,NO-GLUE,

    DNS Report http://www.dnsreport.com/ 的在线工具在校验某域名配置时,parent nameservers 部分老是有 Glue at parent nameservers 即 NO GLUE 的警告。
    看了网页上的简短说明,也不是非常明白所谓的 NO GLUE 到底是什么概念。翻阅相关书籍,略有斩获,招贴备忘。
    我们知道,按照ICANN/IANA的协调:
        COM. NET. 2个域的 nameservers 是 a.gtld-servers.net. b.gtld-servers.net. 等 A-M 13台服务器。
        CN 和 COM.CN. 等中国国家的ccTLDs 的 nameservers 是 a.dns.cn. b.cns.cn. 等6台服务器。
    第一种情况:比如我们申请到域名 domain.com.,在域名配置的控制面板可以注册并添加多条 NS RRs,如 ns1.domain.com. ns2.domain.com.等。这些新添加的 NS RRs 在其 parent nameservers 将以如下的方式存在:
domain.com.       IN  NS    ns1.domain.com.
domain.com.       IN  NS    ns2.domain.com.
ns1.domain.com.   IN   A    xxx.xxx.xxx.xxx
ns2.domain.com.   IN   A    xxx.xxx.xxx.xxx
    即,我们可以使用类似这样的命令:
        nslookup -q=any ns1.domain.com. a.gtld-servers.net.
        nslookup -q=ns domain.com. a.gtld-servers.net.
    直接在 a.gtld-servers.net. 处查询(非递归)到 domain.com. 相关的 NS RRs 以及对应的IP地址,这种情况就是 GLUE 的。

    第二种情况:比如我们申请到域名 domain.com.,我们使用域名注册商提供的,且已经存在的 NS 来负责解析此域名,比如中国万网的 dns7.hichina.com. dns8.hichina.com.,这个时候在其 parent nameservers 将以如下的方式存在:
domain.com.       IN  NS    dns7.hichina.com.
domain.com.       IN  NS    dns8.hichina.com.
    由于这是2台已经注册过的 nameservers , 即还有:
dns7.hichina.com.    IN   A    xxx.xxx.xxx.xxx
dns8.hichina.com.    IN   A    xxx.xxx.xxx.xxx
    dns7.hichina.com. dns8.hichina.com.和 domain.com. 同属于一个 TLDs,所以我们在向 a.gtld-servers.net. 查询(非递归) domain.com. 相关 NS RRs以及对应IP地址时,a.gtld-servers.net. 都能给出正确应答,这种情况也是 GLUE 的。

    第三种情况:比如我们申请到中国国家域名 newdomain.cn.,我们使用域名注册商提供的 NS 来负责解析此域名,比如中国万网的 dns7.hichina.com. dns8.hichina.com.,这时 domain.cn.的相关NS在其 parent nameservers a.dns.cn中将以如下的方式存在:
newdomain.cn.       IN  NS    dns7.hichina.com.
newdomain.cn.       IN  NS    dns8.hichina.com.
    由于 dns7.hichina.com. dns8.hichina.com.和 newdomain.cn. 不是同属于一个 TLDs,所以我们在向 a.dns.cn. 查询(非递归) newdomain.cn. 相关 NS RRs以及对应IP地址时,a.dns.cn. 只都能给出 NS 记录,不能给出其对应 IP 地址,需要我们再另外一次的递归查询才能得到对应 IP 地址。这种情况就是 NO GLUE 的。

    另外还有一种特殊的情况,类似第二种情况,目标域名和 nameservers 的所属域名是同一个 TLDs 的,比如都是 COM. 的,但这几个 nameservers 没有在所属域名的 parent nameservers 中注册过,那么这种情况也应当是 NO GLUE 的。
   
    总结一句话,在同一个 TLDs 的 parent namservers 上直接可以查询到目标域名相关的 NS RRs 以及 NS 对应的 IP 地址的情况就是 GLUE ,否则就是 NO GLUE。虽然 NO GLUE 略微会造成解析上的延迟,但不是致命的问题。有条件的域名建议使用 GLUE 的 NS。
    另外: DNS Report 的工具在诊断 COM.CN.中国国家域名是否 GLUE 上有一点小小的问题,实用的时候,可以斟酌看待。

Wednesday, October 12, 2016

Python in Xcode 7 - Stack Overflow

?? how can run with "Debug executable" on?

Python in Xcode 7 - Stack Overflow


244
down vote
accepted
I figured it out! The steps make it look like it will take more effort than it actually does.

These instructions are for creating a project from scratch. If you have existing Python scripts that you wish to include in this project, you will obviously need to slightly deviate from these instructions.

If you find that these instructions no longer work or are unclear due to changes in Xcode updates, please let me know. I will make the necessary corrections.

Open Xcode. The instructions for either are the same.
In the menu bar, click “File” → “New” → “New Project…”.
Select “Other” in the left pane, then "External Build System" in the right page, and next click "Next".
Enter the product name, organization name, or organization identifier.
For the “Build Tool” field, type in /usr/local/bin/python3 for Python 3 or /usr/bin/python for Python 2 and then click “Next”. Note that this assumes you have the symbolic link (that is setup by default) that resolves to the Python executable. If you are unsure as to where your Python executables are, enter either of these commands into Terminal: which python3 and which python.
Click “Next”.
Choose where to save it and click “Create”.
In the menu bar, click “File” → “New” → “New File…”.
Select “Other” under “OS X”.
Select “Empty” and click “Next”.
Navigate to the project folder (it will not work, otherwise), enter the name of the Python file (including the “.py” extension), and click “Create”.
In the menu bar, click “Product” → “Scheme” → “Edit Scheme…”.
Click “Run” in the left pane.
In the “Info” tab, click the “Executable” field and then click “Other…”.
Navigate to the executable from Step 6. You may need to use ⇧⌘G to type in the directory if it is hidden.
Select the executable and click "Choose".
Uncheck “Debug executable”. If you skip this step, Xcode will try to debug the Python executable itself. I am unaware of a way to integrate an external debugging tool into Xcode.
Click the “+” icon under “Arguments Passed On Launch”. You might have to expand that section by clicking on the triangle pointing to the right.
Type in $(SRCROOT)/ (or $(SOURCE_ROOT)/) and then the name of the Python file you want to test. Remember, the Python program must be in the project folder. Otherwise, you will have to type out the full path (or relative path if it's in a subfolder of the project folder) here. If there are spaces anywhere in the full path, you must include quotation marks at the beginning and end of this.
Click “Close”.
Note that if you open the "Utilities" panel, with the "Show the File inspector" tab active, the file type is automatically set to "Default - Python script". Feel free to look through all the file type options it has, to gain an idea as to what all it is capable of doing. The method above can be applied to any interpreted language. As of right now, I have yet to figure out exactly how to get it to work with Java; then again, I haven't done too much research. Surely there is some documentation floating around on the web about all of this.

Running without administrative privileges:

If you do not have administrative privileges or are not in the Developer group, you can still use Xcode for Python programming (but you still won't be able to develop in languages that require compiling). Instead of using the play button, in the menu bar, click "Product" → "Perform Action" → "Run Without Building" or simply use the keyboard shortcut ^⌘R.

Other Notes:

To change the text encoding, line endings, and/or indentation settings, open the "Utilities" panel and click "Show the File inspector" tab active. There, you will find these settings.

For more information about Xcode's build settings, there is no better source than this. I'd be interested in hearing from somebody who got this to work with unsupported compiled languages. This process should work for any other interpreted language. Just be sure to change Step 6 and Step 16 accordingly.

Wednesday, October 5, 2016

A Celery-like Python Task Queue in 55 Lines of Code

A Celery-like Python Task Queue in 55 Lines of Code: A Celery-like Python Task Queue in 55 Lines of Code



A Celery-like Python Task Queue in 55 Lines of Code

Update: you can check this out on GitHub here.
Celery is probably the best known task queuing Python package around. It makes asynchronous execution of Python code both possible and reasonably straightforward. It does, however, come with a good deal of complexity, and it's not as simple to use as I would like (i.e. for many use cases it's overkill). So I wrote a distributed Python task queue. In 55 lines of code (caveat: using two awesome libraries).

Background

What does a distributed task queue do? It takes code like the following (taken from the documentation forRQ, another Celery alternative):
import requests

def count_words_in_page(url):
    resp = requests.get(url)
    return len(resp.text.split())
and allows it to be sent to a worker process (possibly on another machine) for execution. The worker process then sends back the results after the calculation is complete. In the meantime, the sender doesn't have to block waiting for the (possibly expensive) calculation to complete. They can just periodically check if the results are ready.
So what's the absolute simplest way we could do this? I submit to you, brokest.py:
"""Broker-less distributed task queue."""
import pickle

import zmq
import cloud

HOST = '127.0.0.1'
PORT = 9090
TASK_SOCKET = zmq.Context().socket(zmq.REQ)
TASK_SOCKET.connect('tcp://{}:{}'.format(HOST, PORT))

class Worker(object):
    """A remote task executor."""

    def __init__(self, host=HOST, port=PORT):
        """Initialize worker."""
        self.host = host
        self.port = port
        self._context = zmq.Context()
        self._socket = self._context.socket(zmq.REP)

    def start(self):
        """Start listening for tasks."""
        self._socket.bind('tcp://{}:{}'.format(self.host, self.port))
        while True:
            runnable_string = self._socket.recv_pyobj()
            runnable = pickle.loads(runnable_string)
            self._socket.send_pyobj('')
            args = self._socket.recv_pyobj()
            self._socket.send_pyobj('')
            kwargs = self._socket.recv_pyobj()
            response = self._do_work(runnable, args, kwargs)
            self._socket.send_pyobj(response)

    def _do_work(self, task, args, kwargs):
        """Return the result of executing the given task."""
        print('Running [{}] with args [{}] and kwargs [{}]'.format(
            task, args, kwargs))
        return task(*args, **kwargs)

def queue(runnable, *args, **kwargs):
    """Return the result of running the task *runnable* with the given 
    arguments."""
    runnable_string = cloud.serialization.cloudpickle.dumps(runnable)
    TASK_SOCKET.send_pyobj(runnable_string)
    TASK_SOCKET.recv()
    TASK_SOCKET.send_pyobj(args)
    TASK_SOCKET.recv()
    TASK_SOCKET.send_pyobj(kwargs)
    results = TASK_SOCKET.recv_pyobj()
    return results

if __name__ == '__main__':
    w = Worker()
    w.start()
And to use it? Here's the complete contents of app.py:
import requests
from brokest import queue

def count_words_in_page(url):
    resp = requests.get(url)
    return len(resp.text.split())

result = queue(count_words_in_page, 'http://www.jeffknupp.com')
print result
Rather than calling the function directly, you simply call brokest.queue with the function and it arguments as arguments. While the current implementation is blocking, it would be trivially easy to make it non-blocking. Adding multiple workers is just a matter of adding code to make use of a config file with their locations.
Clearly, the stars here are zmq and cloud. ZeroMQ makes creating distributed systems a lot easier, and the documentation is chock full of ZeroMQ design patterns (ours is probably the simplest one, Request-Reply).
cloud is the LGPL'd PiCloud library. PiCloud is a company whose value proposition is that they let you seamlessly run computationally intensive Python code using Amazon EC2 for computing resources. Part of making that a reality, though, required a way to pickle functions and their dependencies (functions are not normally directly pickle-able). In our example, the Worker is able to make use of code using requestslibrary despite not having imported it. It's the secret sauce that makes this all possible.

Is This For Real?

The code works, but my intention was not to create a production quality distributed task queue. Rather, it was to show how new libraries are making it easier than ever to create distributed systems. Having a way to pickle code objects and their dependencies is a huge win, and I'm angry I hadn't heard of PiCloud earlier.
One of the best things about being a programmer is the ability to tinker not just with things, but with ideas. I can take existing ideas and tweak them, or combine existing ideas in new ways. I think brokest is an interesting example of how easy it has become to create distributed systems.
Posted on  by 

Discuss Posts With Other Readers at discourse.jeffknupp.com!

Like this article?

Why not sign up for Python Tutoring? Sessions can be held remotely using Google+/Skype or in-person if you're in the NYC area. Email jeff@jeffknupp.com if interested.
Sign up for the free jeffknupp.com email newsletter. Sent roughly once a month, it focuses on Python programming, scalable web development, and growing your freelance consultancy. And of course, you'll never be spammed, your privacy is protected, and you can opt out at any time.

Wednesday, August 17, 2016

A successful Git branching model � nvie.com

A successful Git branching model � nvie.com
A successful Git branching model
By Vincent Driessen
on Tuesday, January 05, 2010

We Provide the Highest Level of Transparency & Control for Cloud
ads via Carbon
In this post I present the development model that I’ve introduced for some of my projects (both at work and private) about a year ago, and which has turned out to be very successful. I’ve been meaning to write about it for a while now, but I’ve never really found the time to do so thoroughly, until now. I won’t talk about any of the projects’ details, merely about the branching strategy and release management.



It focuses around Git as the tool for the versioning of all of our source code. (By the way, if you’re interested in Git, our company GitPrime provides some awesome realtime data analytics on software engineering performance.)

Why git?
For a thorough discussion on the pros and cons of Git compared to centralized source code control systems, see the web. There are plenty of flame wars going on there. As a developer, I prefer Git above all other tools around today. Git really changed the way developers think of merging and branching. From the classic CVS/Subversion world I came from, merging/branching has always been considered a bit scary (“beware of merge conflicts, they bite you!”) and something you only do every once in a while.

But with Git, these actions are extremely cheap and simple, and they are considered one of the core parts of your daily workflow, really. For example, in CVS/Subversion books, branching and merging is first discussed in the later chapters (for advanced users), while in every Git book, it’s already covered in chapter 3 (basics).

As a consequence of its simplicity and repetitive nature, branching and merging are no longer something to be afraid of. Version control tools are supposed to assist in branching/merging more than anything else.

Enough about the tools, let’s head onto the development model. The model that I’m going to present here is essentially no more than a set of procedures that every team member has to follow in order to come to a managed software development process.

Decentralized but centralized
The repository setup that we use and that works well with this branching model, is that with a central “truth” repo. Note that this repo is only considered to be the central one (since Git is a DVCS, there is no such thing as a central repo at a technical level). We will refer to this repo as origin, since this name is familiar to all Git users.



Each developer pulls and pushes to origin. But besides the centralized push-pull relationships, each developer may also pull changes from other peers to form sub teams. For example, this might be useful to work together with two or more developers on a big new feature, before pushing the work in progress to origin prematurely. In the figure above, there are subteams of Alice and Bob, Alice and David, and Clair and David.

Technically, this means nothing more than that Alice has defined a Git remote, named bob, pointing to Bob’s repository, and vice versa.

The main branches


At the core, the development model is greatly inspired by existing models out there. The central repo holds two main branches with an infinite lifetime:

master
develop
The master branch at origin should be familiar to every Git user. Parallel to the master branch, another branch exists called develop.

We consider origin/master to be the main branch where the source code of HEAD always reflects a production-ready state.

We consider origin/develop to be the main branch where the source code of HEAD always reflects a state with the latest delivered development changes for the next release. Some would call this the “integration branch”. This is where any automatic nightly builds are built from.

When the source code in the develop branch reaches a stable point and is ready to be released, all of the changes should be merged back into master somehow and then tagged with a release number. How this is done in detail will be discussed further on.

Therefore, each time when changes are merged back into master, this is a new production release by definition. We tend to be very strict at this, so that theoretically, we could use a Git hook script to automatically build and roll-out our software to our production servers everytime there was a commit on master.

Supporting branches
Next to the main branches master and develop, our development model uses a variety of supporting branches to aid parallel development between team members, ease tracking of features, prepare for production releases and to assist in quickly fixing live production problems. Unlike the main branches, these branches always have a limited life time, since they will be removed eventually.

The different types of branches we may use are:

Feature branches
Release branches
Hotfix branches
Each of these branches have a specific purpose and are bound to strict rules as to which branches may be their originating branch and which branches must be their merge targets. We will walk through them in a minute.

By no means are these branches “special” from a technical perspective. The branch types are categorized by how we use them. They are of course plain old Git branches.

Feature branches


May branch off from:
develop
Must merge back into:
develop
Branch naming convention:
anything except master, develop, release-*, or hotfix-*
Feature branches (or sometimes called topic branches) are used to develop new features for the upcoming or a distant future release. When starting development of a feature, the target release in which this feature will be incorporated may well be unknown at that point. The essence of a feature branch is that it exists as long as the feature is in development, but will eventually be merged back into develop (to definitely add the new feature to the upcoming release) or discarded (in case of a disappointing experiment).

Feature branches typically exist in developer repos only, not in origin.

Creating a feature branch
When starting work on a new feature, branch off from the develop branch.

$ git checkout -b myfeature develop
Switched to a new branch "myfeature"
Incorporating a finished feature on develop
Finished features may be merged into the develop branch to definitely add them to the upcoming release:

$ git checkout develop
Switched to branch 'develop'
$ git merge --no-ff myfeature
Updating ea1b82a..05e9557
(Summary of changes)
$ git branch -d myfeature
Deleted branch myfeature (was 05e9557).
$ git push origin develop
The --no-ff flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature. Compare:



In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Reverting a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easily done if the --no-ff flag was used.

Yes, it will create a few more (empty) commit objects, but the gain is much bigger than the cost.

Release branches
May branch off from:
develop
Must merge back into:
develop and master
Branch naming convention:
release-*
Release branches support preparation of a new production release. They allow for last-minute dotting of i’s and crossing t’s. Furthermore, they allow for minor bug fixes and preparing meta-data for a release (version number, build dates, etc.). By doing all of this work on a release branch, the develop branch is cleared to receive features for the next big release.

The key moment to branch off a new release branch from develop is when develop (almost) reflects the desired state of the new release. At least all features that are targeted for the release-to-be-built must be merged in to develop at this point in time. All features targeted at future releases may not—they must wait until after the release branch is branched off.

It is exactly at the start of a release branch that the upcoming release gets assigned a version number—not any earlier. Up until that moment, the develop branch reflected changes for the “next release”, but it is unclear whether that “next release” will eventually become 0.3 or 1.0, until the release branch is started. That decision is made on the start of the release branch and is carried out by the project’s rules on version number bumping.

Creating a release branch
Release branches are created from the develop branch. For example, say version 1.1.5 is the current production release and we have a big release coming up. The state of develop is ready for the “next release” and we have decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we branch off and give the release branch a name reflecting the new version number:

$ git checkout -b release-1.2 develop
Switched to a new branch "release-1.2"
$ ./bump-version.sh 1.2
Files modified successfully, version bumped to 1.2.
$ git commit -a -m "Bumped version number to 1.2"
[release-1.2 74d9424] Bumped version number to 1.2
1 files changed, 1 insertions(+), 1 deletions(-)
After creating a new branch and switching to it, we bump the version number. Here, bump-version.sh is a fictional shell script that changes some files in the working copy to reflect the new version. (This can of course be a manual change—the point being that some files change.) Then, the bumped version number is committed.

This new branch may exist there for a while, until the release may be rolled out definitely. During that time, bug fixes may be applied in this branch (rather than on the develop branch). Adding large new features here is strictly prohibited. They must be merged into develop, and therefore, wait for the next big release.

Finishing a release branch
When the state of the release branch is ready to become a real release, some actions need to be carried out. First, the release branch is merged into master (since every commit on master is a new release by definition, remember). Next, that commit on master must be tagged for easy future reference to this historical version. Finally, the changes made on the release branch need to be merged back into develop, so that future releases also contain these bug fixes.

The first two steps in Git:

$ git checkout master
Switched to branch 'master'
$ git merge --no-ff release-1.2
Merge made by recursive.
(Summary of changes)
$ git tag -a 1.2
The release is now done, and tagged for future reference.

Edit: You might as well want to use the -s or -u flags to sign your tag cryptographically.

To keep the changes made in the release branch, we need to merge those back into develop, though. In Git:

$ git checkout develop
Switched to branch 'develop'
$ git merge --no-ff release-1.2
Merge made by recursive.
(Summary of changes)
This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit.

Now we are really done and the release branch may be removed, since we don’t need it anymore:

$ git branch -d release-1.2
Deleted branch release-1.2 (was ff452fe).
Hotfix branches


May branch off from:
master
Must merge back into:
develop and master
Branch naming convention:
hotfix-*
Hotfix branches are very much like release branches in that they are also meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version. When a critical bug in a production version must be resolved immediately, a hotfix branch may be branched off from the corresponding tag on the master branch that marks the production version.

The essence is that work of team members (on the develop branch) can continue, while another person is preparing a quick production fix.

Creating the hotfix branch
Hotfix branches are created from the master branch. For example, say version 1.2 is the current production release running live and causing troubles due to a severe bug. But changes on develop are yet unstable. We may then branch off a hotfix branch and start fixing the problem:

$ git checkout -b hotfix-1.2.1 master
Switched to a new branch "hotfix-1.2.1"
$ ./bump-version.sh 1.2.1
Files modified successfully, version bumped to 1.2.1.
$ git commit -a -m "Bumped version number to 1.2.1"
[hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
1 files changed, 1 insertions(+), 1 deletions(-)
Don’t forget to bump the version number after branching off!

Then, fix the bug and commit the fix in one or more separate commits.

$ git commit -m "Fixed severe production problem"
[hotfix-1.2.1 abbe5d6] Fixed severe production problem
5 files changed, 32 insertions(+), 17 deletions(-)
Finishing a hotfix branch

When finished, the bugfix needs to be merged back into master, but also needs to be merged back into develop, in order to safeguard that the bugfix is included in the next release as well. This is completely similar to how release branches are finished.

First, update master and tag the release.

$ git checkout master
Switched to branch 'master'
$ git merge --no-ff hotfix-1.2.1
Merge made by recursive.
(Summary of changes)
$ git tag -a 1.2.1
Edit: You might as well want to use the -s or -u flags to sign your tag cryptographically.

Next, include the bugfix in develop, too:

$ git checkout develop
Switched to branch 'develop'
$ git merge --no-ff hotfix-1.2.1
Merge made by recursive.
(Summary of changes)
The one exception to the rule here is that, when a release branch currently exists, the hotfix changes need to be merged into that release branch, instead of develop. Back-merging the bugfix into the release branch will eventually result in the bugfix being merged into develop too, when the release branch is finished. (If work in develop immediately requires this bugfix and cannot wait for the release branch to be finished, you may safely merge the bugfix into develop now already as well.)

Finally, remove the temporary branch:

$ git branch -d hotfix-1.2.1
Deleted branch hotfix-1.2.1 (was abbe5d6).
Summary
While there is nothing really shocking new to this branching model, the “big picture” figure that this post began with has turned out to be tremendously useful in our projects. It forms an elegant mental model that is easy to comprehend and allows team members to develop a shared understanding of the branching and releasing processes.

A high-quality PDF version of the figure is provided here. Go ahead and hang it on the wall for quick reference at any time.

Update: And for anyone who requested it: here’s the gitflow-model.src.key of the main diagram image (Apple Keynote).


Git-branching-model.pdf

If you want to get in touch, I'm @nvie on Twitter.