TL;DR: Branch only from master, merge back when done and immediately deploy.
Git proposes a branch system with the possibility to merge them together, allowing you to separate released code from work in progress one.
mastermust always be deployable.
- all changes are made through feature branches (pull-request + merge)
- rebase to avoid/resolve conflicts; merge in to
Working on a change
Changes can be new features, bug fixes, enhancements. They're all coming from master:
git checkout master git checkout -b my-changes
Making the change ready
Once you're happy with your branch, you need to update it with the last changes from master:
git checkout master git pull --rebase git checkout my-changes git rebase master git push -fu origin my-changes
rebasewill rewrite your commits, their dates will be changed (therefore their hash will be changed).
Check your tests, the coding standards and ask for a code review.
You can list conflicts (if any):
Edit your files and then mark them as solved:
git add <file>
When all conflicted files have been resolved, you can continue:
git rebase --continue
When to merge
Here's a to do list you can use to know if a branch is ready to be merged:
- is it compliant with the coding standards?
- has the code been reviewed?
- do the tests pass?
- has the Quality Assurance team checked the feature?
- will someone be available in the next hour in case of emergency?
- does the product owner want this feature now?
Deploying the new change
If everything is ok with your change, then you can merge it into master:
git checkout master git merge --no-ff my-change git push git push origin :my-changes git branch -D my-changes
It's now time to deploy! You can make a tag:
git tag -a <version> git push --tags
Make small changes, release often.