Branching and merging best practices in Git
While Git Flow is an excellent branching model, the questions you are asking are a symptom of a bigger problem: Git Flow is too heavy for a small team working on a consumer web product (I am making an assumption that you are working on consumer web product, feel free to ignore if you are coding nuclear power plant control room).
I would like to encourage you to consider Continuous Deployment (CD) with an extremely simple branching model:
It is very easy to setup CD nowadays:
- Use Travis, CodeShip, Jenkins or similar system to run a full build and test suite on every commit pushed on every branch of your codebase
- Setup Travis/Codeship/Jenkins to deploy to production every commit to master that passes the tests.
- Create a new branch from
master
for every new feature. - Code a new feature and test it on a branch.
- Merge a feature branch into
master
, and watch it go live.
There are a lot of common objections to it, that all can be summarized as "but what if I introduce a bug?!". The answer is "You'll fix it!". If you write tests, if you monitor your production site, if you do code reviews, if you practice pair programming, if you use feature flags, and if you keep your features small, then the benefits you get from CD will outweigh the occasional problems any day.
I encourage you to try. It will free your mind to focus on what truly matters: building a great product! If you do not believe me, take a look at this excellent presentation from Github.
This always depends on how do you want to work and the team agreement. That said.
- A feature starts from the dev branch into its own branch. From the master branch you should only branch hotfixes because the master branch should always be the stable version of your software.
- When a feature branch is done, it should be merged into dev, then at some point you should branch your next release from dev (including some features) into a new 'release/*' branch which will be merged into master once it is stabilized and well tested.
In the Atlassian page you have a very nice explanation of this workflow
The whole idea with this kind of workflows is to have a stable version branch in which you can work and fix any bug immediately if you need to with enough confidence that it will still be stable and no new feature or refactorization will slip in without noticing.
Also to have isolation and freedom for each new feature which will be developed in its own branch with no noise from other features. Then finally you will merge your features into your dev branch and from there into the master branch for the next release.
The only thing I would recommend for you is to learn how to rebase your feature branches on top of the dev branch each time another feature is merged into dev to avoid resolving conflicts on merge time, but in isolation on the feature branch where you know what your changes are.
It also looks like this question was asked before