Real world Git workflows
TODO Show of hands � Picture with hands/lighter/concert
Stefan Saasen Atlassian Stash Development Lead
Stefan Saasen Atlassian Stash Development Lead @stefansaasen
You heard is on the rise 38% 15% from 2011 to 2013 Source: RedMonk Git Survey 2013
You heard has Cheap local branching Full local history Much faster than svn Staging area Huge community Speed Superior Merging prominent in Open Source Distributed cryptographic integrity
We’ll cover:
We’ll cover: Collaboration model 1
We’ll cover: Collaboration model 1 Branching model 2
We’ll cover: Collaboration model 1 Branching model 2 Practices 3
Which collaboration model? 1
Slide Title
ANARCHY Fully decentralized Anarchy
I do my thing, too I do my thing ANARCHY here’ s mine, who tells look ma, a goat! john? Fully decentralized Anarchy
Gatekeeper Blessed repository with Gatekeeper
He is cool Gatekeeper Blessed repository with Gatekeeper To have your work accepted, talk to him
Dictator and Lieutenants
Dictator and Lieutenants Blessed repository long live the King! Lieutenants guard the King
Centralised Shared common repository
Centralised Shared common repository we share “everything”
+
+ Enterprise
= Centralized + Enterprise
Metrics Issues Builds Deployments
Metrics Issues Builds They know where the code needs to go! Deployments
Which branching model?
Which branching model? 2
Can we still fix a bug for the upcoming Release ?
Can we still fix a bug for the upcoming Release ? Is the code for that Feature complete?
Hotfix How do we do a Can we still fix a bug for the upcoming Release ? for the current version? Is the code for that Feature complete?
Hotfix How do we do a Can we still fix a bug for the upcoming Release ? for the current version? Is the code for that Feature Reviewed Has everyone complete? the code for this feature ?
What’s the best Git workflow?
We don’ t know! What’s the best Git workflow?
What’s the best Git workflow? di ff erent cultures
What’s the best Git workflow? di ff erent cultures + di ff erent products
What’s the best Git workflow? di ff erent cultures + di ff erent products + di ff erent teams
What’s the best Git workflow? di ff erent cultures + di ff erent products + di ff erent teams = di ff erent workflows
Design your own Workflows
1. Single branch workflow - aka trunk
Committing locally Local Repository Master
Committing locally Local Repository Master
Central repository has updates Master Central Repository Local Repository Master
Getting updates via rebase Master Central Repository Local Repository Master
Getting updates via rebase Master Central Repository Local Repository Master
2. Feature branching workflow
Creating a branch master
Creating a branch master Feature #1
Adding changes master Feature #1
Merge master m Feature #1
Working on features in parallel Feature #2 master m Feature #1
Working on features in parallel Feature #2 master m Feature #1
Suboptimal way Feature #2 m e l b i s s o p master m f i s i h t d Feature #1 i o v a
Suboptimal way e Feature #2 m l b i s s o p f m master m i s i h t d i o Feature #1 v a
A better way using rebase Feature #2 master m Feature #1
Working on features in parallel m Feature #2 m master m Feature #1
Working on features in parallel m Feature #2 m master m Feature #1
Working on features in parallel m Feature #2 m master m Feature #1 •Always with local branches
Working on features in parallel m Feature #2 m master m Feature #1 •Always with local branches •With shared branches: After review, before merging
Working on features in parallel m Feature #2 m master m Feature #1 •Always with local branches •With shared branches: After review, before merging •Mostly a non-issue for short lived branches when updates from master are not required
3. Continuous delivery workflow
master is in production 1
promoted from staging, can receive hot-fixes master is in production 1
promoted from staging, can receive hot-fixes master is in production 1 staging is the next version 2
promoted from staging, can receive hot-fixes master is in production 1 staging is the next version 2 new features o ff staging 3
promoted from staging, can receive hot-fixes master is in production 1 staging is the next version 2 new features o ff staging 3 with branch names like: username/ISSUE-KEY-summary
3. Continuous delivery workflow feature-1 m staging master
3. Continuous delivery workflow feature-1 feature-2 m m m staging master
3. Continuous delivery workflow feature-1 feature-2 m m m staging m master
3. Continuous delivery workflow feature-1 feature-2 m m m staging m master H R
3. Continuous delivery workflow feature-1 feature-2 m m m staging m master H R release to production = merge master In Production
3. Continuous delivery workflow only merges feature-1 feature-2 m m m staging m master H R release to production = merge master In Production
4. Product releases workflow
one branch per feature 1
one branch per feature 1 one branch per bugfix 2
one branch per feature 1 one branch per bugfix 2 long running stable branches 3
one branch per feature 1 one branch per bugfix 2 long running stable branches 3 master is alpha/RC status 4
it’s just a normal branching workflow… feature-1 feature-2 master
with long running release branches feature-1 feature-2 master 2.2 2.1 bugfix
Bugfix Merge Master 2.2 2.1 Bugfix
Merge into 2.1 Master 2.2 2.1 Bugfix
Merge into 2.2 Master 2.2 2.1 Bugfix
Merge into Master Master 2.2 2.1 Bugfix
Automatically merging release branches Master 2.2 2.1 Bugfix
Automatically merging release branches Master 2.2 2.1 Bugfix Automatic MERGES!
Automatically merging release branches 2.1.4 2.1.5-SNAPSHOT We don’ t want to merge the 2.1.x version! 2.2 2.1 Bugfix
git merge --strategy= resolve
git merge --strategy= recursive
git merge --strategy=
git merge --strategy= ours
Automatically merging release branches 2.1.4 2.1.5-SNAPSHOT 2.2 2.1 Bugfix $> git checkout stable-2.2 $> git merge -s ours stable-2.1
Automatically merging release branches merge commit, content discarded 2.2 2.1 Bugfix $> git checkout stable-2.2 $> git merge -s ours stable-2.1
overall picture feature-1 feature-2 master 2.2 2.1 bugfix
Deep breath, it’s really simple
Recommend
More recommend