Real World

Workflows
Nicola Paolucci

Developer Advocate / Git Evangelist

I come out nice in pictures, I know :-).

durdn.com

@durdn
You heard

has
Cheap local branching

Full local history

10x the speed of svn

Staging area
Speed

Huge community
Feature based workflow

prominent in Open Source
cryptographic integrity

Distributed
ground breaking paradigm
is ground breaking
Workflow building blocks
fork

cheap branching

rebase
powerful merging
distributed
clone
Can we do a fast
Can we fix a bug for the
upcoming

RELEASE

HOTFIXrelease?
for the current

?
Can we

BUILD

the current code ?
Is the code for that

FEATURE
complete?

Has everybody

REVIEWED ?
the code for this feature
What we’ll cover:
What we’ll cover:
1

Branching models
What we’ll cover:
1

Branching models

2

Practices & Decisions
What we’ll cover:
1

Branching models

2

Practices & Decisions

3

Tooling & Automation
What we’ll cover:
1

Branching models

2

Practices & Decisions

3

Tooling & Automation

4

Continuous Integration
Which branching model?
1

Which branching model?
Two common Branching Models
Two common Branching Models
1

Continuous Delivery
Two common Branching Models
1

Continuous Delivery

2

Product Releases
for Continuous Delivery
1.1

for Continuous Delivery
Time

feature

staging

master/
production
staging

Time

feature

master/
production

master is in production
staging

Time

feature

master/
production

master is in production
staging is the next version
staging

Time

feature

master/
production

master is in production
staging is the next version
new features off staging
with branch names like:
username/ISSUE-KEY-summary
staging

Time

feature

master/
production

master is in production
PR

staging is the next version
new features off staging
with branch names like:
username/ISSUE-KEY-summary
staging

promoted from staging, can receive hotfixes

Time

feature

master/
production

master is in production
PR

staging is the next version
new features off staging
with branch names like:
username/ISSUE-KEY-summary
staging

promoted from staging, can receive hotfixes

Time

feature

master/
production

master is in production
PR

staging is the next version
new features off staging
with branch names like:

Hotfix

username/ISSUE-KEY-summary
staging

promoted from staging, can receive hotfixes

Time

feature

master/
production

master is in production
PR

staging is the next version
new features off staging
with branch names like:

Hotfix

username/ISSUE-KEY-summary
for Product Releases
1.2

for Product Releases
1

One Central Repository
master

PRJ-123-description

Time

feature
branches

1

One Central Repository

2

One Branch per Feature
PRJ-123-bug-description

Time

bugfix
branch

master

1

One Central Repository

2

One Branch per Feature

3

One Branch per Bugfix
2.2

PRJ-345-bug-description

Time

bugfix
release
branch
master
master

2.2

PRJ-345-bug-description

Time

bugfix

release
branch

4

Release Branches
master

Long running

2.2

PRJ-345-bug-description

Time

bugfix

release
branch

4

Release Branches
master

Long running

2.2

PRJ-345-bug-description

Time

bugfix

release
branch

4

Release Branches

5

master is alpha / RC
Automatic merges for the win!
release
branch

release
branch

2.1

2.2

PRJ-345-bug-description

Time

bugfix

master
Automatic MERGES!

release
branch

release
branch

2.1

2.2

PRJ-345-bug-description

Time

bugfix

master
Automatic MERGES!

release
branch

release
branch

2.1

2.2

PRJ-345-bug-description

Time

bugfix

master
Automatic MERGES!

release
branch

release
branch

2.1

2.2

PRJ-345-bug-description

Time

bugfix

master
Placeholder for changes you DON’T want to merge!
release
branch

release
branch

2.1

2.2

2.2.1
release
branch

release
branch

2.1

2.2

2.2.1

2.1.4
release
branch

release
branch

2.1

2.2

2.2.1

2.1.4
2.1.5-SNAPSHOT
release
branch

release
branch

2.1

2.2

2.2.1

2.1.4
2.1.5-SNAPSHOT

We don’t want to merge
the 2.1.x version!
release
branch

release
branch

2.1

2.2

2.2.1

2.1.4
2.1.5-SNAPSHOT

What can we do here?

We don’t want to merge
the 2.1.x version!
git merge
git merge --strategy= resolve
git merge --strategy= recursive
git merge --strategy=
git merge --strategy= ours
stable
branch

stable
branch

2.1

2.2

2.2.1

2.1.4
2.1.5-SNAPSHOT
stable
branch

stable
branch

2.1

2.2

2.2.1

2.1.4
2.1.5-SNAPSHOT

$> git checkout stable-2.2
$> git merge -s ours stable-2.1
stable
branch

stable
branch

2.1

2.2

2.2.1

2.1.4
2.1.5-SNAPSHOT

$> git checkout stable-2.2
$> git merge -s ours stable-2.1

merge commit, content
discarded
Deep breath, it’s really simple
The secret sauce

The merge protocol
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

Less stable than its
baseline

When code complete

Continuously
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

Less stable than its
baseline

When code complete

Continuously
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
Feature branches
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
Feature branches
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
Feature branches
The secret sauce

The merge protocol
When a branch is:

Change flows from
branch to baseline:

Change flows from baseline
to branch:

More stable than its
baseline

Continuously

Never

When code complete

Continuously

Release branch

Less stable than its
baseline
Feature branches

Credit: Laura Wingerd - The Flow of change
The secret sauce

The merge protocol
Release Branch

Master
The secret sauce

The merge protocol
Release Branch
Merge
continuously

Master
The secret sauce

The merge protocol
Release Branch
Never

Merge

merge!

continuously

Master
The secret sauce

The merge protocol
Release Branch
Never

Merge

merge!

continuously

Master

Backport single
changes using
git cherry-pick
Practices & Decisions
turbo boost!

2

Practices & Decisions
What is a Pull Request?
Pull Request
I have some
code here!

Hey I have some code I
want to merge here,
take a look?

Low friction
collaboration

Can I merge
it here?
Merge vs Rebase
Does a debate even exist?

REBASE

MERGE
What is a Rebase?
feature

master
What is a Rebase?
Merge commit
feature

master
What is a Rebase?
Merge commit
feature

master

feature

master
What is a Rebase?
Merge commit
feature

master

feature

master
What is a Rebase?
Merge commit
feature

master

feature

master
What is a Rebase?
Merge commit
feature

master

feature

master
Merge as team policy
Merge as team policy
1

Traceability
Merge as team policy
1

Traceability

2

At a cost: readability
Merge as team policy
1

Traceability

2

At a cost: readability

3

bisect debugging is harder
Merge as team policy
with no fast-forwards

1

Traceability

2

At a cost: readability

3

bisect debugging is harder
Rebase as team policy [1]
Rebase as team policy [1]
1

History flat and clean
Rebase as team policy [1]
1

History flat and clean

2

Delicate with Pull Requests
Rebase as team policy [1]
1

History flat and clean

2

Delicate with Pull Requests

3

Dangerous for unexperienced
Rebase as team policy [2]
Rebase as team policy [2]
4

Re-resolve similar conflicts
Rebase as team policy [2]
4

Re-resolve similar conflicts

5

Requires often a force push
Rebase as team policy [2]
4

Re-resolve similar conflicts

5

Requires often a force push

6

Loses context for feature
Rebase as a local cleanup
Rebase as a local cleanup
1

Do it
Rebase as a local cleanup
git rebase --interactive
1

Do it
Rebase as a local cleanup
git rebase --interactive
1

Do it

2

Do it
Rebase as a local cleanup
git rebase --interactive
1

Do it

2

Do it

3

Do it!!!!!!
Recommendation?
Recommendation?
1

If team unfamiliar, don’t rebase
Recommendation?
1

If team unfamiliar, don’t rebase

2

Encourage rebase as cleanup

and proper ecology
Recommendation?
1

If team unfamiliar, don’t rebase

2

Encourage rebase as cleanup

and proper ecology

3

Choose clean or traceable
Recommendation?
Recommendation?
4

Don’t fear the Merge! Use it!
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!

git log --first-parent
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!

git log --first-parent

5

May rebase feature branches
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!

git log --first-parent

5

May rebase feature branches

To update the feature branch
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!

git log --first-parent

After review!

5

May rebase feature branches

To update the feature branch
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!

git log --first-parent

After review!

5

May rebase feature branches

To update the feature branch

6

Work with the tool!
Recommendation?
Explicit merges into the mainline

4

Don’t fear the Merge! Use it!

git log --first-parent

After review!

5

May rebase feature branches

To update the feature branch

6

Work with the tool!
Trying to strive for a linearized history is less useful than you think
Single Repository
vs
Remote Forks
With Forks
Every one has their
remote repository
With Forks
Every one has their
remote repository

Full remote copy,
each has one

Integrator, Gatekeeper,
Tech Lead, etc.
Pros of a Single Repo
Pros of a Single Repo
1

Complete visibility
Pros of a Single Repo
All feature
branches
available

1

Complete visibility
Pros of a Single Repo
All feature
branches
available

1

Complete visibility

2

No per Dev remotes required
Pros of a Single Repo
All feature
branches
available

1

Complete visibility

2

No per Dev remotes required

3

KISS
Forks
Are Great too BTW
FORKING
IN THE

ENTERPRISE
FORKING IN

5 Reasons for...

ENTERPRISE
FORKING IN

ENTERPRISE

REASON 1

Great for customizing libraries
FORKING IN

ENTERPRISE

REASON 1

Great for customizing libraries
and still get bug fixes
FORKING IN

ENTERPRISE

REASON 2

Great for innovation spikes
FORKING IN

ENTERPRISE

REASON 2

Great for innovation spikes
and maybe add it later
FORKING IN

ENTERPRISE

REASON 3

Protecting your components
FORKING IN

but still be open for changes

REASON 3

Protecting your components

ENTERPRISE
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
Tooling & Automation
3

Tooling & Automation
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
pre-/post-applypatch
pre-/post-commit

Remote
pre-receive
update

pre-rebase

post-receive

post-checkout

post-update

post-merge
pre-push
Code Quality
via pre-commit hooks
.git/hooks/pre-commit
git add -u
git 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 master
master 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

?
1

What happens to CI with git?
1

What happens to CI with git?

2

An explosion of branches
1

What happens to CI with git?

2

An explosion of branches

3

Performance degradation of build sys
1

Building everything is expensive
1

Building everything is expensive

2

Automatically build stable and master
1

Building everything is expensive

2

Automatically build stable and master

3

Manually trigger feature branch builds
In Conclusion: the recipe
Conclusions
Collaboration
Model

Branching
Model

Practices &
Decisions

Automation &
CI setup
Conclusions
Collaboration
Model

Centralized

Branching
Model

Practices &
Decisions

Automation &
CI setup
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Centralized

Practices &
Decisions

Automation &
CI setup
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Centralized
Continuous
delivery
workflow

Practices &
Decisions

Automation &
CI setup
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Centralized
Continuous
delivery
workflow

Practices &
Decisions

Embrace PR

Automation &
CI setup
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Practices &
Decisions

Embrace PR
Merge vs

Centralized
Continuous
delivery
workflow

Rebase

Automation &
CI setup
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Practices &
Decisions

Embrace PR
Merge vs

Centralized
Continuous

Rebase

delivery
workflow

Single Repo
or Forks

Automation &
CI setup
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Practices &
Decisions

Embrace PR
Merge vs

Centralized
Continuous

Rebase

delivery
workflow

Single Repo
or Forks

Automation &
CI setup
Hooks, hooks
everywhere
Conclusions
Collaboration
Model

Branching
Model
Product
workflow

Practices &
Decisions

Embrace PR
Merge vs

Centralized
Continuous

Rebase

delivery
workflow

Single Repo
or Forks

Automation &
CI setup
Hooks, hooks
everywhere
Build
automatically,
but leave
knobs!
Nicola Paolucci

THANK YOU FOR YOUR ATTENTION!

Should I change the pic? ;-)

durdn.com

@durdn
Atlassian
Git Repository Management
for Enterprise Teams
Free Git Code Hosting
for Small Teams
Free Git Desktop client
for Mac or Windows

Real World Git Workflows - EclipseCon Europe 2013