Gitflow is a great workflow to ensure you maintain constant ever increasing version numbers with enough room to fix mistakes. The downside is the slowness of deploying new features. GitFlowSimple is a simplified version which can be expanded to standard GitFlow when needed, but is less effort when deploying new features.
This method assumes the following are true:
- You understand the following features of git
- How to branch from a non-HEAD commit
- How to deal with a merge conflict
- That linear history is an illusion (so you use
git log -a --graph).
- You understand what is meant by a “SNAPSHOT” version. Basically, ever changing code which devs can use, but never goes into production.
- You have read and understand GitFlow
- You need to release changes quickly. For example, you are maintaining several projects and need to add features to a library package; GitFlowSimple is ideal for the library.
- You don’t care about contiguous version numbers. The numbers are ever increasing, but may not be in sequence (a use might get 1.2.5 as the update to 1.1.0).
This branching style is ideal for library code that is not normally seen by an end user, or end-user software that is automatically updated since the end-user doesn’t usually keep track of version numbers. You mileage may vary, and you can always migrate to the standard GitFlow workflow when needed.
Where GitFlow has “develop”, “master”, feature, release, and hotfix branches, GitFlowSimple only has “master”, and feature branches (or you can call them release branches if you like merging several features into a release). Everything that is done on the extra GitFlow branches is be done directly on a feature branch or master branch in GitFlowSimple.
The main branch
“master” is the only main branch and (just like GitFlow) it must remain production ready. And just like GitFlow this is the branch where version tags are created.
Unlike GitFlow this is also the branch where version numbers are bumped. The flow looks a little bit like this:
- HEAD is version 1.0 (which is also tagged)
- A feature branch is created from the HEAD commit of master
- The feature is bumped into a snapshot image as follows:
- The version file (inside the source code) is updated to 1.1.0-SNAPSHOT
- The change is committed, immediately
- The change and the feature branch are pushed to the central repo
- The feature is developed
- The feature is tested and merged (
git merge --no-ff)
- On master, the version is bumped as follows:
- The Version file is updated to 1.1.0 (no “-SNAPSHOT”)
- The change is committed
- The change is tagged
- All changes are pushed to the central repo
--no-ff prevents git from linear-izing the commits and
makes it easy (using
git log -a --graph) to see all the
The hotfix and feature branches are both used in GitFlowSimple. The two branches serve the same purpose as they do in GitFlow. The release branch serves no function in GitFlowSimple.
GitFlowSimple is best shown using an example. Lets assume the project is currently at 1.0, and a defect that popped up needs to be fixed, and at the same time two new features need to be added. I am going to deal with each in turn, but in actuality they will be done in parallel.
- A hotfix branch is created using the 1.0 tag (unlike GitFlow which would have used the “master” branch for this). The branch is called “hotfix-1.0.1”.
- The version file is updated to “1.0.1-SNAPSHOT” and committed.
- The branch is pushed
- The defect is fixed (which takes 10 commits)
- The defect is tested
Now we need to merge to master and claim the rightful version number.
- The code is merged to master
- On master the version is updated to “1.0.1”
- The change is committed
- The commit is tagged “1.0.1”
- The commit and tag are pushed to origin
Started at the same time as the Hotfix.
- A feature branch is created using master’s HEAD (currently 1.0.0) is created named “feature-1”.
- The version file is updated to “1.1.0-SNAPSHOT” and committed.
- The branch is pushed
- The feature is added (which takes 3 commits)
Now we need to merge to “master” and create a release, but the Hotfix was already merged.
- The code is merged to master, but fails because of a version file conflict
- The merge is reverted.
- The feature branch is checked out and “master” is merged back into the feature branch.
- The conflict is present again. It is fixed by keeping our “1.1.0-SNAPSHOT” version. Note: we did this because our version was greater then what was in master; see “Feature 2” for what to do when this is not the case.
- We retest before merging to master.
- We attempt the merge to master again. There are no conflicts so we bump the version number as we did with the Hotfix; becoming 1.1.0.
Feature 2 logically started on the 0.9 version so has the 1.0.0-SNAPSHOT version. This feature is not finished until after feature 1 has been merged.
- Master has been pulled
- Master is merged into the feature branch, with a conflict on the version file.
- The conflict is fixed by keeping master’s version: 1.1.0.
- The version number is bumped to 1.2.0-SNAPSHOT (as if this was a new branch based on the current master)
- The code is retested
- The branch is merged into master (as with feature 1 and the hotfix) becoming 1.2.0.
Multiple Same Versions
There is a chance when merging a feature it will not create a merge conflict because it is trying to claim the same version as what is already in master.
This is why it is important to ALWAYS do the following when merging features:
- Merge master back into the feature branch before merging the feature into master.
- Manually update the version number if no merge conflict happened.