EC Repos
Standard Branches¶
clone
master
: serves no purposeLIVE
: Only for use as the currently running live site- Releases (optional):
- Branch from
LIVE
Release-XXX
: For merging feature branches into for testing on a Staging site
- Branch from
- Features:
- Branch from
LIVE
JIR-123-Description-of-Feature
: Feature branch. Merged into Release-00x or dev when the feature is considered stable- Subfeatures
- Branch from a Feature
JIR-123-JIR-124-Description-of-Subfeature
- Branch from
Grouping tasks into Releases¶
Jira
You can also use Jira to mirror these branches
- Releases are an optional addition to the system that make sense for projects where a lot of concurrent tasks are worked on
- When using Release branches, the Release represents a group of completed Features ready for testing.
- Features should only be merged into the Release once they're ready for testing - a Release should never have half-finished features merged into it.
- A Release must be deployed to
LIVE
as a whole package. When assigning Features to Releases make sure any dependencies are within the same Release, and also be aware that one unfinished feature will hold up the entire Release. - Releases numbers should be incrememented as they're created (not their intended release order, as that can change)
Testing code on Staging¶
- If using a Staging site, it should be a
git checkout
ed working copy of the Release or Feature you want to be tested. - This allows for switching between Releases or Features as and when they're in development
Git Branch lifecycle¶
Working in Feature branches¶
git checkout LIVE
to make sure you're branching from the live site- Create a new feature branch with
git checkout -b JIR-100-Ticket-Summary
- In Jira mark the ticket as In Progress
- Commit early, commit often. The Feature branch can be in a broken state
Considerations:
- Each ticket should be its own git branch, prefixed with the Jira ticket number
- Multiple Feature branches can be worked on in parallel until they're complete
- Branch dependencies should be documented in Jira using Issue Links
Preparing completed features for Release¶
Note
Release branches are optional. If not using Releases the Feature can be merged into LIVE
directly, but the same workflow below applies
- Add a new Release in Jira
git checkout LIVE
to make sure you're branching from the live sitegit checkout -b Release-XXX
your new Release branchgit merge
your features you intend to deploy toLIVE
- Make sure to add the Release to the ticket's "Fix Version" field
- Remember to
git branch -d
the Feature branches after they've been merged in
git commit
any fixes into the Release branch that need to be made before going live
Considerations:
- This branch should represent everything that will go live. This branch should be checked out onto the Staging site for acceptance testing
- Ideally commits should stay inside the Feature branches, but I acknowledge that this is going to add a lot of overhead
Putting the Release live¶
git checkout Release-XXX
git merge LIVE
to make sure anyLIVE
changes are in the Release- If these are significant, you might need another round of testing
git checkout LIVE
git merge Release-XXX
git tag Release-XXX
git branch -d Release-XXX
git push
yourLIVE
branch andgit pull
it onto the server
Considerations:
- Once a Feature (via a Release) is merged into LIVE, that Feature branch is then considered immutable; new items should be new tickets/branches
- You may choose to tag the merge commit as the Release name for easy rollback
Subfeatures¶
Sometimes one feature will need to be separated out into smaller subfeatures, and therefore branches.
git checkout JIR-123-Ticket-Description
to make sure you're branching from the parent feature- Create a new subfeature branch with
git checkout -b JIR-123/JIR-124-Ticket-Summary
- Commit into the subfeature branch, and feel free to re-merge the parent into the subfeature
- Once the subfeature is complete, it must be merged back into its parent feature and then deleted
Considerations:
- The hierarchy should be clear in the
JIR-123/JIR-124
branch name prefix - We're allowing for 3 levels of branching, with a max name of
JIR-123/JIR-124/JIR-125-Sub-Sub-Branch-Name
- The hierarchy is explicitly not coupled to Jira ticket types; the top level doesn't have to be an Epic, and the bottom level doesn't have to be a subtask
- Subfeatures must clearly depend on the parent feature to function
- Subfeatures cannot end up in the
LIVE
branch other than via their parent branch.
Hotfixes¶
Hotfixes are for quick fixes to urgent problems. They're intended to remove the overhead of Releases when time is critical
git checkout LIVE
to make sure you're branching from LIVEgit checkout -b JIR-XXX-Problem-Hotfix
to create the hotfix branch- Make changes in that branch
git checkout
the branch onto a dev site for testinggit checkout LIVE
and thengit merge JIR-XXX-Problem-Hotfix
git branch -d
your Hotfix branch- Push your changes to the live site
Considerations:
- A hotfix should address a discrete problem; if the scope is large you should use a Feature and follow the standard release procedure
- Hotfix branches are technically identical to Feature branches, so if the scope becomes large, it can be treated the same
Overview¶
When this has been going for a while, you'll have multiple parallel features and multiple concurrent Releases:
FAQs¶
Why are we deleting branches?¶
On a long running project the list of Feature- and Release branches can become huge. This can make tab-completion and branch differentiation more difficult.
When merged branches are deleted, it then becomes clear that existant branches are only those being actively being worked on
What if I want to trace the branch's history?¶
Remember that a branch is just a label for a specific commit. When you git checkout
a specific branch, all you're checking out the commit that that branch name is assigned to.
Deleting a branch doesn't actually delete the history associated with it. If you check the history (using git log --graph
, gtk, or PHPStorm's VCS log), you'll see where it was forked from its parent, the commits that happened, and where it was merged back in.
Can I keep my branches locally?¶
Your local git repo nis your own and can contain whatever branches you like. Just remember to not push up your local branches to the remotes.
What if I've merged my features and now my Release has bugs?¶
If bugs are found in the release, either commit directly into the Release branch, or sub-branch from the Release:
- Branch off the Release with
git checkout -b Release-001/MAG-123-Bugfix-the-Release
git commit
your bugfixing until you're satisfied it's sortedgit checkout
your Release branchget merge
yourRelease-001/MAG-123-Bugfix-the-Release
sub-branchgit branch -d
yourRelease-001/MAG-123-Bugfix-the-Release
sub-branch
What do I do if my Release is way too broken and I want remove a Feature from it?¶
If you've merged a few features into a Release and it's clear you're not going to quickly resolve the problems, it's time to abandon that Release
Because unpicking the commits merged from one particular branch is too cumbersome, you'll need to reinstate your Feature branches and create a new Release
- Find the last commit that represents your feature and copy its commit hash
- Remember that when you deleted the branch, all you did was delete the label - the branch itself remains in the reflog
- You can find this tree structure using
git log --branch
, gitk, or PHPStorm's VCS log
git checkout <commit_hash>
for the commit hash you want to reinstategit checkout -b MAG-123-Original-Branch-Name
, which will reassign the branch-name label to that commit- Repeat the above until the branch names for all branches are reinstated
git branch -D
the Release branch you're abandoning- You can then create a new Release and merge in all but the problematic Feature