Multi-Branch Flow
This workflow works well with 2-5 people when you want to maintain different environments.
With this workflow we will be dealing with two permanent branches: main and develop along with feature branches.
Start your day
- Start on the
developbranch
git checkout develop
git pull origin develop
Create a feature branch
Branch off develop
git checkout develop
git checkout -b feature/my-branch
feature/my-branch is the name of your feature branch. It can be named anything, but here are common naming examples:
- feature/add-homepage
- bugfix/fix-login-error
- chore/organize-files
- docs/document-setup
Work on your feature
- Make changes locally
- Stage and commit
git add .
git commit -m "add a commmit message here"
Keep your feature branch up-to-date (optional)
If you are working with others it is a good idea to merge develop back into your feature branch to keep your feature branch up to date with changes others have made.
git checkout develop
git pull origin develop
git checkout feature/my-branch
git merge develop
If merge conflicts appear you will need to resolve them.
Push your feature branch
When you are ready to bring your feature branch into develop push your feature branch to your git host.
git push origin feature/my-branch
Open a pull request (PR) into develop
- Log into your git host
- Opean a PR to merge your feature branch into
develop - Request review from teammates if needed
- After approval, merge into
develop - After merge is complete you can delete your feature branch from your git host
develop can be used as an integration branch to test everyone’s changes together. You can also use it to deploy to a “dev” or “staging” environment where you can test changes before merging to main and going to production.
Merge develop into main for production
Once develop is stable and tested, merge into main
- Log into your git host
- Create a PR from
developintomain - Request review and approval if needed
- When approved merge the PR
- Do not delete
developafter the merge.developshould remain as your integration branch.
Clean up
After your feature branch is merged into develop you can delete it.
git checkout develop
git pull origin develop
git branch -d feature/my-branch
If you did not delete your branch after you merged the PR on your git host you can delete it with:
git push origin --delete feature/my-branch
Hotfixes
Sometimes you need to fix something in production immediately. For these cases you can branch off main, creating a feature branch (i.e. hotfix/fix-typo) and then create PRs to merge the hotfix branch back into main and develop.