- [A successful Git branching model](#a-successful-git-branching-model) - [Main Branches](#main-branches) - [Supporting brach](#supporting-brach) - [Feature Branches](#feature-branches) - [Creating a feature branch](#creating-a-feature-branch) - [After finishing the feature and merge back to develop](#after-finishing-the-feature-and-merge-back-to-develop) - [Release Branches](#release-branches) - [Creating release branch](#creating-release-branch) - [Finishing release branch](#finishing-release-branch) - [Hotfix Branches](#hotfix-branches) - [Creating hotfix branch](#creating-hotfix-branch) - [Finishing hotfix branch](#finishing-hotfix-branch) - [Information](#information) # A successful Git branching model ![Model](https://monosnap.com/image/Zi2H8mClwH1UrV29xiNCKFF4Qifa1d) ## Main Branches - master - develop ## Supporting brach - Release - Hotfix - Feature ## Feature Branches Feature branches are used to develop a new feature for an upcoming or distant future release. **Feature branches only exist in developers repos only i.e. in their machine, not in origin i.e. remote.** - branch from develop - must be merged back in develop - Naming convention -> Anything except - master - develop - release-* - hotfix-* ### Creating a feature branch ![Creating Feature](https://monosnap.com/image/UwyzArE4iLJ6xyPszZHLzDqE0dhMBD) #### After finishing the feature and merge back to develop ![Compare](https://monosnap.com/image/Qfy4caGCECu1HCRwbJuArf7kfD0fSg) **Sourcetree Version** ![SourceTree after finishing p1](https://monosnap.com/image/W87JP66Hww2nRV7JrzdwKY2ntgTaRN) ![p2](https://monosnap.com/image/JJoVkDLiyXnhruM19WNTWIoKKWVV0L) Take pull before pushing your code if pull is available. ![p3](https://monosnap.com/image/KGNxtRHKCIa7PvbvEm0MkoRMzqNAXK) It is impossible to see from git history of which commit objects together implement a feature. You would have to manually read all commit messages. If you need to revert particular feature, it is true headache in later situations, whereas it is easy with --no-ff flag was used. It will create more empty commits but the gain is much bigger than cost. ## Release Branches - Branch from develop - Must merge back in **develop** and **master** - Branch naming conventions - release-* ### Creating release branch ![Release1](https://monosnap.com/image/y4Nw93AqSLISGltiEWMNicOoK0orF2) You have to collect release notes from commit you can type one. Bump version to 1.2.1 as matches with your release branch name. ### Finishing release branch ![Finishing Release](https://monosnap.com/image/CRbcGlgAZNrFTsB2rYtYBVi6xw2jk4) To keep changes made by release branch, we need to merge in develop ![Finishing off](https://monosnap.com/image/MjnbcROfDRabF3ZalnGEMxydFgtCL2) This may lead to merge conflict. If so, fix and commit it. ## Hotfix Branches - Branch from master - Must merge back in __develop__ and __master__ - Branch naming conventions - hotfix-* Hotfix branches are very much like release branches in that they are meant to prepare for production, albeit unplanned. When a critical bug in production version must be resolved immediately, a hotfix branch may be branch of from corresponding tag on master branch that marks production version. ![Hotfix Branch](https://monosnap.com/image/LIqSvuJyDTrLR0Huf2HVaQhyCmqVFa) ### Creating hotfix branch ![Creating hotfix](https://monosnap.com/image/bpdkQ1LZjg1dGaWV00iMrJ2Qhm5vbe) Don't forget to bump a version after branching off. Then fix the bug and commit changes ### Finishing hotfix branch When finished the bug fixed, we need to merge back in master as well as develop branch, in order to safeguard that the bug fix also include in next release as well. ![Finishing Hotfix](https://monosnap.com/image/GdoyVCYzW4TL2wLK5XZ2NO6hWvnj4t) The one exception rule is that, **When a release branch currently exists, the hotfix branch need to be merge in release branch instead of develop.** Back merging the bug fix into release branch eventually result in the hotfix branch merge in _**develop**_ too, when release branch is finished. __(If work in develop immediately require the hotfix and cannot wait it fo release branch to finish, you can safely merge in develop branch now already as well.)__ ## Information ![Information](https://monosnap.com/image/5dUZ5mA4aefyXf1k5QYfvWn9aXF4JS) You can find full documentation and explanation [here](https://nvie.com/posts/a-successful-git-branching-model/). Feel free to check it out. Other links to learn and embrace the power of Git. 1. [Git documentation](https://git-scm.com/doc) 2. [Git tutorial](https://git-scm.com/docs/gittutorial) 3. [Git dev docs](https://devdocs.io/git/) 4. [Git tutorial and training](https://www.atlassian.com/git/tutorials) 5. [Git power tools for daily use](https://nvie.com/posts/git-power-tools/)