Git workflow for small teams
A finely tuned git workflow can save you an enormous amount of time over the long run. Over time, I have improved my development process by trying out multiple different strategies. I wanted to share the process I’m currently using that has proven to be successful in a small team environment.
I choose to keep things as simple as possible and use the story branch pattern. All development gets worked on in a local feature branch and pushed to a single remote development branch. Releases are tagged and deployed to production from the master branch. The general workflow for a feature involves the following:
- Create a new branch off of development named after the feature.
- Work on my feature, continuously committing at regular intervals to keep track of what I’ve done.
- Keep my local feature branch up to date from any upstream changes my team has made. This needs to happen often to stay fresh.
- Once finished, wrap all of my tiny commits into a single, pretty commit.
- Merge local feature branch into development and push it up for the rest of the team.
- Delete the feature branch, as it is no longer needed.
If you perform all of those steps manually, it can get quite cumbersome over time and you may find yourself or your team taking shortcuts and not sticking to the process. Fortunately, a lot of this can be automated if you are consistent.
Set up your remote branch
Create a remote development branch from your master branch and track it locally. This is what the team will collaborate on:
git push origin master:refs/heads/development git checkout --track origin/development
Get to it!
Start working on a new feature
git checkout -b my_cool_feature
Make some changes
touch part1.txt && git add part1.txt git commit -m "Adding first part of new feature" touch part2.txt && git add part2.txt git commit -m "Adding second part"
Make sure you are up to date with the latest from the remote development branch. Roll your local changes on top of them:
git checkout development git pull git checkout my_cool_feature git rebase development
Wrap up all of your local commits you’ve made into one commit by performing an interactive rebase:
git rebase -i development
When your editor opens, combine all commits into one by squashing every commit into the first:
pick ae3a3dc Adding first part of new feature squash 3c82ad8 Adding second part
Now pretty up your single commit message :
[#123456] My Cool New Feature * Adding first part * Adding second part
Merge your feature into development, push it up for your team, and delete your local branch
git checkout development git merge my_cool_feature git push origin development git branch -d my_cool_feature
Repeat for every other feature
Once all features for a release are ready to be shipped out, perform the following:
Merge development into master
git checkout master git merge development
Tag the release (I version my projects using the major.minor.patch versioning)
git tag 1.0.0
Push up your changes
git push git push --tags
Find a bug?
What happens if a bug is found in production? My general process for handling this involves the following:
- Make the fix directly on master
- Tag it as a patch release
- Push up the change
- Merge the change into development