real world git workflows - eclipsecon europe 2013
DESCRIPTION
While Git is established in the Open Source world, we're only just seeing the emergence of DVCS in our daily jobs. How can DVCS enable us to collaborate in a traditional "enterprise" setting. Atlassian has fully embraced DVCS and has started to build features into their suite of products to take advantage of this new and exciting paradigm. The talk will dive deep into the successful git work flows used inside Atlassian. There is no size fit all for this topic and various effective processes can be devised and are in active used at our company. The talk will also cover tools and techniques used to reduce friction during the development of features and bugfix releases like for example pre/post receive hooks and automatic merges. Outline: * Software Development Practices And DVCS - Branch vs fork (single server/repo, vs forks) - Code quality (pre-commit hook, pre-checkout hook, pre-receive, see below) * Awesome Git Workflows Used Internally At Atlassian - Continuous Delivery Branching model - Product Releases Branching model * Streamlining Your Git Process - merge vs rebase - Rebase as cleanup - Meaningful merges - hooks . hooks in general . Post-checkout checks . pre-commit hooks . Great Pre-receive and Post-receive hooks - Automatic merges * How does CI change when you move to git?TRANSCRIPT
Real World Workflows
Nicola PaolucciDeveloper Advocate / Git Evangelist
@durdndurdn.comI come out nice in pictures, I know :-).
Cheap local branchingFull local history
Speed
Staging area
prominent in Open Source
Huge community
You heard has
Feature based workflow
10x the speed of svn
Distributedcryptographic integrity
ground breaking paradigm is ground breaking
Workflow building blocks
rebasepowerful merging
fork
clone
cheap branching
distributed
RELEASECan we fix a bug for the
upcoming?
FEATUREIs the code for that
complete?
BUILDCan we
the current code ?
REVIEWEDHas everybody
the code for this feature ?
HOTFIXCan we do a fast
for the current release?
What we’ll cover:
1
What we’ll cover:
Branching models
Practices & Decisions
1
2
What we’ll cover:
Branching models
Practices & Decisions
1
2
What we’ll cover:
Branching models
Tooling & Automation3
Practices & Decisions
1
2
What we’ll cover:
Branching models
Tooling & Automation3
4 Continuous Integration
Which branching model?
Which branching model?1
Two common Branching Models
1 Continuous Delivery
Two common Branching Models
Product Releases
1 Continuous Delivery
2
Two common Branching Models
for Continuous Delivery
1.1 for Continuous Delivery
Tim
emaster/
productionstagingfeature
Tim
emaster/
productionstagingfeature
master is in production
Tim
emaster/
productionstagingfeature
master is in production
staging is the next version
Tim
emaster/
productionstagingfeature
master is in production
staging is the next version
new features off staging
with branch names like: username/ISSUE-KEY-summary
Tim
emaster/
productionstagingfeature
master is in production
staging is the next version
new features off staging
with branch names like: username/ISSUE-KEY-summary
PR
Tim
emaster/
productionstagingfeature
master is in production
staging is the next version
new features off staging
with branch names like: username/ISSUE-KEY-summary
promoted from staging, can receive hotfixes
PR
Tim
emaster/
productionstagingfeature
master is in production
staging is the next version
new features off staging
with branch names like: username/ISSUE-KEY-summary
promoted from staging, can receive hotfixes
Hotfix
PR
Tim
emaster/
productionstagingfeature
master is in production
staging is the next version
new features off staging
with branch names like: username/ISSUE-KEY-summary
promoted from staging, can receive hotfixes
Hotfix
PR
for Product Releases
for Product Releases1.2
One Central Repository1
One Central Repository1
One Branch per Feature2
Tim
emasterfeature
branches
PRJ-
123-
desc
ript
ion
One Central Repository1
One Branch per Feature
One Branch per Bugfix
2
3
Tim
emasterbugfix
branch
PRJ-
123-
bug-
desc
ript
ion
Tim
emasterrelease
branch
PRJ-
345-
bug-
desc
ript
ion
bugfix
2.2
Release Branches4
Tim
emasterrelease
branch
PRJ-
345-
bug-
desc
ript
ion
bugfix
2.2
Release Branches4
Long running
Tim
emasterrelease
branch
PRJ-
345-
bug-
desc
ript
ion
bugfix
2.2
Release Branches4
master is alpha / RC5
Long running
Tim
emasterrelease
branch
PRJ-
345-
bug-
desc
ript
ion
bugfix
2.2
Automatic merges for the win!
PRJ-
345-
bug-
desc
ript
ion
Tim
e
release branch
master
2.2
release branch
bugfix
2.1
PRJ-
345-
bug-
desc
ript
ion
Tim
e
release branch
master
2.2
release branch
bugfix
2.1
Automatic MERGES!
PRJ-
345-
bug-
desc
ript
ion
Tim
e
release branch
master
2.2
release branch
bugfix
2.1
Automatic MERGES!
PRJ-
345-
bug-
desc
ript
ion
Tim
e
release branch
master
2.2
release branch
bugfix
2.1
Automatic MERGES!
Placeholder for changes you DON’T want to merge!
release branch
2.2
release branch
2.1
2.2.1
release branch
2.2
release branch
2.1
2.1.4
2.2.1
release branch
2.2
release branch
2.1
2.1.4
2.2.1
2.1.5-SNAPSHOT
release branch
2.2
release branch
2.1
2.1.4
2.2.1
We don’t want to merge the 2.1.x version!
2.1.5-SNAPSHOT
release branch
2.2
release branch
2.1
2.1.4
2.2.1
We don’t want to merge the 2.1.x version!
2.1.5-SNAPSHOT
What can we do here?
git merge
git mergegit merge --strategy= resolve
git merge --strategy= recursive
git merge --strategy=
git merge --strategy= ours
stable branch
2.2
stable branch
2.1
2.1.4
2.2.1
2.1.5-SNAPSHOT
stable branch
2.2
stable branch
2.1
2.1.4
2.2.1
2.1.5-SNAPSHOT
$> git checkout stable-2.2$> git merge -s ours stable-2.1
stable branch
2.2
stable branch
2.1
2.1.4
2.2.1
2.1.5-SNAPSHOT
merge commit, content discarded$> git checkout stable-2.2
$> git merge -s ours stable-2.1
Deep breath, it’s really simple
The merge protocolThe secret sauce
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
Feature branches
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
Feature branches
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
Feature branches
The merge protocolThe secret sauce
When a branch is: Change flows from branch to baseline:
Change flows from baseline to branch:
More stable than its baseline
Less stable than its baseline
Continuously Never
When code complete Continuously
Release branch
Release branch
Feature branchesCredit: Laura Wingerd - The Flow of change
The merge protocolThe secret sauce
Release branch
Release Branch
Master
The merge protocolThe secret sauce
Release branch
Release Branch
Master
Mergecontinuously
The merge protocolThe secret sauce
Release branch
Release Branch
Master
Mergecontinuously
Never merge!
The merge protocolThe secret sauce
Release branch
Release Branch
Master
Mergecontinuously
Backport single changes using git cherry-pick
Never merge!
Practices & Decisions
Practices & Decisions2
turbo boost!
What is a Pull Request?
Hey I have some code I want to merge here,
take a look?
Low friction collaboration
Pull Request
I have some code here!
Can I merge it here?
Does a debate even exist?
Merge vs Rebase
MER
GE REBA
SE
What is a Rebase?
master
feature
What is a Rebase?Merge commit
master
feature
master
feature
What is a Rebase?Merge commit
master
feature
master
feature
What is a Rebase?Merge commit
master
feature
master
feature
What is a Rebase?Merge commit
master
feature
master
feature
What is a Rebase?Merge commit
master
feature
Merge as team policy
Traceability1
Merge as team policy
Traceability1
At a cost: readability2
Merge as team policy
Traceability1
At a cost: readability2
3
Merge as team policy
bisect debugging is harder
Traceability1
At a cost: readability2
3
Merge as team policy
bisect debugging is harder
with no fast-forwards
Rebase as team policy [1]
History flat and clean1
Rebase as team policy [1]
History flat and clean1
Delicate with Pull Requests2
Rebase as team policy [1]
History flat and clean1
Delicate with Pull Requests
Dangerous for unexperienced
2
3
Rebase as team policy [1]
Rebase as team policy [2]
Re-resolve similar conflicts4
Rebase as team policy [2]
Re-resolve similar conflicts4
Requires often a force push5
Rebase as team policy [2]
Re-resolve similar conflicts4
Requires often a force push
Loses context for feature
5
6
Rebase as team policy [2]
Rebase as a local cleanup
Do it1
Rebase as a local cleanup
Do it1
Rebase as a local cleanup
git rebase --interactive
Do it1
Do it2
Rebase as a local cleanup
git rebase --interactive
Do it1
Do it
Do it!!!!!!
2
3
Rebase as a local cleanup
git rebase --interactive
Recommendation?
If team unfamiliar, don’t rebase1
Recommendation?
If team unfamiliar, don’t rebase1
Encourage rebase as cleanup2
Recommendation?
and proper ecology
If team unfamiliar, don’t rebase1
Encourage rebase as cleanup
Choose clean or traceable
2
3
Recommendation?
and proper ecology
Recommendation?
Don’t fear the Merge! Use it!4
Recommendation?
Don’t fear the Merge! Use it!4
Recommendation?Explicit merges into the mainline
Don’t fear the Merge! Use it!4
Recommendation?
git log --first-parent
Explicit merges into the mainline
Don’t fear the Merge! Use it!4
May rebase feature branches5
Recommendation?
git log --first-parent
Explicit merges into the mainline
Don’t fear the Merge! Use it!4
May rebase feature branches5
Recommendation?
git log --first-parent
To update the feature branch
Explicit merges into the mainline
Don’t fear the Merge! Use it!4
May rebase feature branches5
Recommendation?
git log --first-parent
To update the feature branch
Explicit merges into the mainline
After review!
Don’t fear the Merge! Use it!4
May rebase feature branches
Work with the tool!
5
6
Recommendation?
git log --first-parent
To update the feature branch
Explicit merges into the mainline
After review!
Don’t fear the Merge! Use it!4
May rebase feature branches
Work with the tool!
5
6
Recommendation?
git log --first-parent
Trying to strive for a linearized history is less useful than you think
To update the feature branch
Explicit merges into the mainline
After review!
Single Repositoryvs
Remote Forks
Every one has their remote repository
With Forks
Every one has their remote repository
With Forks
Full remote copy,each has one Integrator, Gatekeeper,
Tech Lead, etc.
Pros of a Single Repo
Complete visibility1
Pros of a Single Repo
Complete visibility1
Pros of a Single RepoAll feature branches available
Complete visibility1
No per Dev remotes required2
Pros of a Single RepoAll feature branches available
Complete visibility1
No per Dev remotes required
KISS
2
3
Pros of a Single RepoAll feature branches available
Forks Are Great too BTW
FORKING IN THE
ENTERPRISE
FORKING IN
ENTERPRISE5 Reasons for...
FORKING IN
ENTERPRISE
REASON 1
Great for customizing libraries
FORKING IN
ENTERPRISE
REASON 1
Great for customizing librariesand still get bug fixes
REASON 2
Great for innovation spikes
FORKING IN
ENTERPRISE
REASON 2
Great for innovation spikesand maybe add it later
FORKING IN
ENTERPRISE
REASON 3
Protecting your components
FORKING IN
ENTERPRISE
REASON 3
Protecting your components
but still be open for changes
FORKING IN
ENTERPRISE
REASON 4
Reduce the noise
FORKING IN
ENTERPRISE
REASON 4
Reduce the noise
and keep the overview for huge projects
FORKING IN
ENTERPRISE
REASON 5
Interaction with Contractors & Interns
FORKING IN
ENTERPRISE
REASON 5
Interaction with Contractors & Interns
protect your sources
FORKING IN
ENTERPRISE
Tooling & Automation
Tooling & Automation3
Hooks
Hooks are little scripts you can place in
the `$GIT_DIR/hooks` directory to trigger
action at certain points.
– githooks Documentation
”“
Pre Post
Local Remote
Local Remotepre-receiveupdatepost-receivepost-update
pre-/post-applypatchpre-/post-commit
pre-rebasepost-checkout
post-mergepre-push
Code Quality via pre-commit hooks
.git/hooks/pre-commit
git add -ugit commit -m "TEST checkstyle"
Starting audit...
/Users/user/[...]/com/atlassian/stash/web/projects/ProjectController.java:161:12: 'for' is not followed by whitespace.
Audit done.Commit aborted.
Branch from green builds
.git/hooks/post-checkout
$ git checkout mastermaster is lookin'good! c4f3b4b has 4 green builds. $ git checkout stable-2.3 DANGER! stable-2.3 is busted. e1324fa has 2 red builds.
Get it at: bitly.com/green-builds
What happens to CI with ?
4 What happens to CI with ?
What happens to CI with git?1
What happens to CI with git?1
An explosion of branches2
What happens to CI with git?1
An explosion of branches2
3 Performance degradation of build sys
Building everything is expensive1
Building everything is expensive1
Automatically build stable and master2
Building everything is expensive1
Automatically build stable and master2
3 Manually trigger feature branch builds
In Conclusion: the recipe
BranchingModel
Practices & Decisions
Automation & CI setup
ConclusionsCollaboration
Model
BranchingModel
Practices & Decisions
Automation & CI setup
ConclusionsCollaboration
Model
Centralized
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
CollaborationModel
Centralized
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
Continuous delivery workflow
CollaborationModel
Centralized
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
Continuous delivery workflow
Embrace PR
CollaborationModel
Centralized
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
Continuous delivery workflow
Embrace PR
CollaborationModel
Centralized Merge vs Rebase
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
Continuous delivery workflow
Embrace PR
Single Repo or Forks
CollaborationModel
Centralized Merge vs Rebase
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
Continuous delivery workflow
Embrace PR
Single Repo or Forks
CollaborationModel
Centralized
Hooks, hooks everywhere
Merge vs Rebase
BranchingModel
Practices & Decisions
Automation & CI setup
Conclusions
Product workflow
Continuous delivery workflow
Embrace PR
Build automatically,
but leave knobs!Single Repo
or Forks
CollaborationModel
Centralized
Hooks, hooks everywhere
Merge vs Rebase
Nicola PaolucciTHANK YOU FOR YOUR ATTENTION!
@durdndurdn.comShould I change the pic? ;-)
Git Repository Management for Enterprise Teams
Free Git Code Hosting for Small Teams
Free Git Desktop client for Mac or Windows
Atlassian