git is a powerful version control tool, while its large amount of commands and options make it hard to use.
So git-flow was created to make git mush convenient. It's a high level branching tools for git.
Fist install it with apt-get install git-flow
on Debian-family distros.
Usage
Workflow on a single feature
The following paragraphs is from [Why aren't you using git-flow?}(http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/).
Branch "master" is always "production ready" code. Commits are never made directly to master. Rather, code on master only gets there after a production release branch is created and "finished" (more on that in a sec). Thus the code on master is always able to be released to production. Also, master is always in a predictable state, so you never need to worry if master (and thus production) has changes one of your other branches doesn't.
"develop" is the branch you'll be doing most of your work off of; it's also the branch that represents the code to be deployed in the next release. feature branches represent non-trivial features and fixes that have not yet been deployed (a completed feature branch is merged back into develop). Updating master is done through the creation of a release.
Most of your work is done on the develop branch. This branch contains all of the completed features and bug fixes yet to be released; nightly builds or continuous integration servers should target develop, as it represents the code that will be included in the next release. For one-off commits, feel free to commit to develop directly.
Use git flow help
or git flow feature help
to list all available commands.
$ git flow init // Convert an existing git repo to git-flow style:
$ git flow feature start <feature-name>
$ git commit -m "now finish this feature"
// if you want cancel this feature:
$ git flow feature // list the current feature name, here is "searchSource"
$ git flow feature delete searchSource
// or do it manually
$ git checkout develop // switch to "develop" branch
$ git branch // list current branches
$ git branch -d feature/<feature-name> // "feature/" is the default prefix of all feature branches
$ git branch // verify the feature is deleted
// push feature to remote repository
$ git flow feature publish
// get feature commit from remote repository
$ git flow feature pull
// after the feature is finished and tested
$ git flow feature finish <feature-name>
Note that do not add "feature/" prefix before feature name. This command merge feature branch back into develop branch, so the feature branch disappear from now on. If you don't want save your feature branch into remote repo, push to remote AFTER you finish your feature with this "finish" command. There is a corresponding "release" command:
$ git flow release start v0.1.0
$ git flow release finish v0.1.0
See git-flow cheatsheet for details of git-flow.
Switching between multiple features
Say you now have finished version 1.0 and tag it with "1.0".
Next you will add function A to the product.
You have two methods to achieve function A, "search source" and "full text".
You want to experiment them one by one, so create the first test branch with git flow feature start searchSource
,
After some commits, now you want to evaluate the second.
You can't git flow feature finish searchSource
for two reasons:
First you may switching back to this feature in the future. If you finish this feature, this branch disappeared.
Second you need experiment "full text" based on version 1.0.
But if you "finish" feature "search source", the modifications will be added to branch develop.
If you git flow feature start fullText
, the codes won't be that in version 1.0.
So what you want is working on multiple branches simultaneously:
$ git flow feature start searchSource
... // some developments on branch searchSource
$ git commit -m "finish a milestone by method search source"
$ git flow feature start fullText
... // some developments on branch fullText
$ git commit -m "finish a milestone by method full text"
$ git flow feature list
$ git flow feature checkout searchSource
... // some developments on branch searchSource
$ git commit -m "finish the 2nd milestone by method search source"
$ git flow feature checkout fullText
... // some developments on branch fullText
$ git commit -m "finish the 2nd milestone by method full text"
If you have some casual modifications which you don't want to commit, use git stash
instead of git commit
.
Use git stash list
to list all stashed changes, and git stash pop
to take the stashed codes out.
Or git stash apply
to take codes out without removing saved stash record.
Finally you choose "full text" to achieve function A.
So add it to your develop code base: git flow feature finish fullText
.
And leave the branch "search source" alone.
If you are sure "search source" are useless any more,
print all existing features with git flow feature list
,
then remove it with git flow feature delete searchSource
.
There is a GUI tool called gitk
, which can be installed with apt-get install gitk
.
See commits on current branch with gitk
, or see all branches with gitk --all
.
There is also a git-flow-completion tool for zsh. Install it if you like.
-
Download _git and replace /usr/share/zsh/functions/Completion/Unix/_git;
-
Download git-flow-completion.zsh, save it as ~/.git-flow-completion.zsh;
-
Add "source ~/.git-flow-completion.zsh" into ~/.zshrc;