Git-flow
This post doesn't try to cover the basics of git-flow nor being a tutorial of how to use it. Instead it's an introduction to the subject and (maybe) a persuasion to use it.
To start, let's describe a common scenario:
Production -> Live (master)
Staging -> Release Candidate (sta)
Development -> Current Development (dev)
Just so you keep track, you'll read the same titles over and over: how to add a feature and how do a hotfix.
The ugly.
Adding a feature
- Pull dev, start coding and then pushing the branch.
- From time to time merge staging and deploy.
- If something isn't working on staging, fix it in that branch.
- If everything under staging is working, merge and push to master, deploy to production.
Bug in production!
- Move to the master branch, fix it.
- Push to master.
- Merge staging and development with master (to have those bug-free).
The good.
Since Staging is our server for testing new features, the sta
branch could be considered as our release candidate branch.
Introducing feature flow
- Create a new branch based on staging.
- If it's needed for collaboration, push the feature branch to origin.
- After it's done, merge it to staging.
- Then, delete the feature branch.
Introducing hotfix flow
- A hotfix is a fix to be done under production.
- Create a new branch base on master.
- Code the fix and the merge it to master and sta.
- After the two merges, delete the hotfix branch.
Until now… If we follow each step, we are using a good workflow.
But the creation, merging and deleting of feature and hotfix branches can be automated.
The better.
Git flow is a git extension. It was created to follow the previous steps in a bliss.
A collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model.
Installing git-flow
In Linux: sudo apt-get install git-flow
In Mac: brew install git-flow
Initialising git-flow.
You'll notice that git has a new command, you can run git flow
to get all the avilable sub-commands.
Run git flow init
in the project to activate Git Flow.
This will prompt for the behaviour to follow on creating branches and for determining each branch purpose.
It doesn't matter in which branch are we now, just remember to have the master and sta branches up to date.
Creating a feature with git flow
git flow feature start <FeatureName>
... code a little bit ...
git add .
git commit -m “This is a good commit”
git flow feature finish <FeatureName>
Creating a hotfix using git flow
git flow hotfix start <HotfixName>
... code the fix ...
git add .
git commit -m “This is an awesome fix”
git flow hotfix finish <HotfixName>
Demanding the use of the same flow could prevent common mistakes. Useful for new members while they're getting closer to the project.
Last thing to mention, Git flow is a convention and you can change it for your needs, just fork it.
I gave a talk about this
Subscribe to RECodes
Get the latest posts delivered right to your inbox