Instead of a single master branch, this workflow uses two branches to record the history of the project. The master branch stores the official release history, and the develop branch serves as an integration branch for features.
We already have a master branch for both projects.
To create a develop branch, which will only be done once by one of the team members, run:
git checkout -b develop
or
git branch develop
Then push to github:
git push -u origin develop
Each new feature should reside in its own branch, which can be pushed to the central repository for backup/collaboration. But, instead of branching off of master, feature branches use develop as their parent branch. When a feature is complete, it gets merged back into develop. Features should never interact directly with master.
git checkout develop
git checkout -b feature/name
After creating the feature branch off develop, you work on that feature to completion and below is the flow you use to push your changes to github.
git add .
git commit -m "commit message here.."
git pull --rebase origin develop
git push origin feature/name
Notice the rebase stage, this stage is usually important to get existing code changes which have already been merged into develop by team members. Here you might run into rebase conflicts if any of the team members worked on same files you have been working on.
Incase of rebase conflicts, kindly review the current change in develop branch and also your incoming code change and accept the correct code changes in that file. After this, follow the next steps to resolve the conflict and push your code changes to github:
git add .
git rebase --continue
git push origin feature/name
After this, just go to github and open a pull request to develop branch, request for reviews from team members and once cleared, your feature will be merged to develop. Then the changes will merged to master by the manager or any other person with the permissions to do this.
Maintenance or “hotfix” branches are used to quickly patch production releases.
hottfix branches are a lot like feature branches except they're based on master instead of develop. This is the only branch that should fork directly off of master. As soon as the fix is complete, it should be merged into both master and develop.
git checkout master
git checkout -b hotfix/branchname
Similar to finishing a release branch, a hotfix branch gets merged into both master and develop.
git add .
git commit -m"hotfix summary"
git pull --rebase origin master
git push origin hotfix/branchname
Then open a pull request from your hotfix branch to master and develop.
The overall flow of Gitflow is:
- A
developbranch is created frommaster Featurebranches are created fromdevelop- When a
featureis complete it is merged into thedevelopbranch - If an issue in
masteris detected ahotfixbranch is created frommaster - Once the
hotfixis complete it is merged to bothdevelopandmaster