October 25, 2018
The Feature Branch Workflow for git is a graduation from the Centralized workflow where all changes are made directly to the master branch.1
Though this is a beginner’s guide to the Feature Branch workflow, it does assume some familiarity with git basics. If you need a refresher, check out my notes from learning git2.
A few rules and guidelines to keep in mind:
There are seven (give or take) steps to the Feature Branch workflow, though steps 3-6 can be repeated multiple times for any given branch.
Get the most up to date master branch.
git checkout master git fetch origin git reset --hard origin/master
Before cutting a branch, you will want to make sure you’re working on the most up to date information.
git checkout -b my-new-feature
In this case the
-b flag tells git to create a new branch (“my-new-feature”) if it doesn’t already exist when you check it out.
Work on your code as you would to build out the new feature.
Because you’re working in a branch, you can push your code to a centralized repository without worry of conflict.
git push -u origin my-new-feature
You only have to do this the first time. Every time after that you want to push a change to a centralized repository for your feature, you can use the more concise
Pull requests are a great opportunity for you to initiate discussion with your colleagues and collaborators.
Use them to get feedback on your feature.
If you receive feedback, you can edit your code locally (returning to step 3. and proceeding as normal).
Once all feedback has been resolved, you’re ready to merge your feature into the main branch.
During this process, you may have to resolve merge conflicts with the master branch. Since the goal is to always have a functioning master branch, this step is crucial to the continuity of the application.
The Git Feature Branch workflow isn’t for every project, but it encourages collaboration and conversation through code review and pull requests. Those are benefits I can get behind.3
Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!