I've been using the git branching strategy outlined here http://nvie.com/posts/a-successful-git-branching-model/
So far its been working really well for me.
The question I often find my self asking is while working on a feature branch I'll end up needing to implement code that is relevant to the entire project. What is the best way to handle these situations?
a) Check out the main development branch, commit the change and rebase the feature branch off of develop.
b) Make the change on the feature branch, then merge back 开发者_高级运维into develop so that other feature branches can have access to that code.
c) Create a new branch for the common code and merge that into Develop as well as any feature branches that need to use it.
Here's another question. How often do you merge a feature branch back into the main development branch? Do you wait until the feature is completely done then merge it and delete it? Or do you merge back into develop several times throughout its lifetime any time that it's stable?
I like option a/, but the reality is, when you are doing commits after commits, you only realize that some of them are actually common code much later in the process.
When that happens on a feature
branch (that usually hasn't been pushed yet and shared with), I prefer doing an interactive rebase
, re-ordering the commits for common code first, and then merging the master
branch to the feature
branch for those n first commits (fast-forward merge).
From there, I can rebase onto master
any other branch that have to benefit from those new common features.
Merging back a feature branch only makes sense if the state of that feature branch must be visible for others (because you want to push master
while keeping feature
branch private to your repo).
If the rest of the development:
- can proceed without needing any part of what is in the
feature
branch - can proceed without modifying some common set of files (which would imply a much harder merge the longer you wait between
master
andfeature
branches)
, then I prefer merging feature
branch later.
精彩评论