144

Real world Git workflows · Real world Git workflows. TODO Show of hands ! Picture with hands/lighter/concert. Stefan Saasen Atlassian Stash Development Lead. Stefan Saasen Atlassian

  • Upload
    others

  • View
    22

  • Download
    0

Embed Size (px)

Citation preview

Real world Git workflows

TODO Show of hands

!Picture with hands/lighter/concert

Stefan SaasenAtlassian Stash Development Lead

Stefan SaasenAtlassian Stash Development Lead

@stefansaasen

15%

38%

from 2011 to 2013Source: RedMonk Git Survey 2013

You heard is on the rise

Cheap local branchingFull local history

Speed

Staging area

prominent in Open Source

Huge community

You heard has

Superior Merging

Much faster than svn

Distributedcryptographic integrity

We’ll cover:

1 Collaboration model

We’ll cover:

1

2

Collaboration model

We’ll cover:

Branching model

1

Practices

2

3

Collaboration model

We’ll cover:

Branching model

Which collaboration model?1

Slide Title

Fully decentralized Anarchy

ANARCHY

Fully decentralized Anarchy

I do my thingI do my thing, too

ANARCHYhere’s mine, who tells

john?look ma, a goat!

Blessed repository with Gatekeeper

Gatekeeper

Blessed repository with Gatekeeper

He is cool

Gatekeeper

To have your work accepted, talk to him

and LieutenantsDictator

and LieutenantsDictator

long live the King!

Lieutenants guard the King

Blessed repository

Shared common repository

Centralised

Shared common repository

we share “everything”

Centralised

+

+

Enterprise

+ = Centralized

Enterprise

Builds

Metrics

Issues

Deployments

Builds

Metrics

Issues

Deployments

They know where the code needs to go!

Which branching model?

Which branching model?2

upcoming Release ?

Can we still fix a bug for the

upcoming Release ?

Can we still fix a bug for the

FeatureIs the code for that

complete?

upcoming Release ?

Can we still fix a bug for the

FeatureIs the code for that

complete?

for the current version?HotfixHow do we do a

upcoming Release ?

Can we still fix a bug for the

FeatureIs the code for that

complete?

for the current version?HotfixHow do we do a

ReviewedHas everyone

the code for this feature ?

Git workflow?What’s the best

Git workflow?What’s the best

We don’t know!

different cultures

Git workflow?What’s the best

+ different productsdifferent cultures

Git workflow?What’s the best

+ different teams+ different products

different cultures

Git workflow?What’s the best

+ different teams+ different products

different cultures

= different workflows

Git workflow?What’s the best

DesignWorkflows

your own

1. Single branch workflow - aka trunk

Committing locally

Master

Local Repository

Committing locally

Master

Local Repository

Central repository has updates

Central Repository

Local Repository

Master

Master

Getting updates via rebase

Central Repository

Local Repository

Master

Master

Getting updates via rebase

Central Repository

Local Repository

Master

Master

2. Feature branching workflow

Creating a branch

master

master

Feature #1

Creating a branch

Adding changes

master

Feature #1

Merge

master

Feature #1

m

Working on features in parallel

master

Feature #1

Feature #2

m

Working on features in parallel

master

Feature #1

Feature #2

m

Suboptimal way

master

Feature #1

Feature #2 m

m

avoid th

is if p

ossible

master

Feature #1

Feature #2 m

m m

avoid th

is if p

ossible

Suboptimal way

A better way using rebase

master

Feature #1

Feature #2

m

Working on features in parallel

master

Feature #1

Feature #2 m

m m

Working on features in parallel

master

Feature #1

Feature #2 m

m m

Working on features in parallel

master

Feature #1

Feature #2 m

m m

•Always with local branches

Working on features in parallel

master

Feature #1

Feature #2 m

m m

•Always with local branches•With shared branches: After review, before merging

Working on features in parallel

master

Feature #1

Feature #2 m

m m

•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 production1

master is in production1

promoted from staging, can receive hot-fixes

master is in production1

staging is the next version2

promoted from staging, can receive hot-fixes

master is in production1

staging is the next version

new features off staging

2

3

promoted from staging, can receive hot-fixes

master is in production1

staging is the next version

new features off staging

2

3

with branch names like: username/ISSUE-KEY-summary

promoted from staging, can receive hot-fixes

staging

master

3. Continuous delivery workflow

feature-1

m

staging

master

feature-2

3. Continuous delivery workflow

m

feature-1

mm

staging

master

feature-2

3. Continuous delivery workflow

m

feature-1

mm m

staging

master

feature-2

3. Continuous delivery workflow

m

feature-1

mm

R H

m

staging

master

feature-2

3. Continuous delivery workflow

m

feature-1

mm

R H

release to production = merge master

In Production

m

staging

master

feature-2

3. Continuous delivery workflow

m

feature-1

mm

R H

only merges

release to production = merge master

In Production

m

4. Product releases workflow

one branch per feature1

one branch per feature1

one branch per bugfix2

one branch per feature1

one branch per bugfix

long running stable branches

2

3

one branch per feature1

one branch per bugfix

long running stable branches

2

3

master is alpha/RC status4

it’s just a normal branching workflow…

master

feature-1

feature-2

with long running release branches

master

2.2

2.1

bugfix

feature-1

feature-2

Master

2.2

Bugfix Merge

2.1

Bugfix

Master

2.2

Merge into 2.1

2.1

Bugfix

Master

2.2

Merge into 2.2

2.1

Bugfix

Master

2.2

Merge into Master

2.1

Bugfix

Master

2.2

2.1

Bugfix

Automatically merging release branches

Master

2.2

2.1

Bugfix

Automatically merging release branches

Automatic MERGES!

2.2

2.1

Bugfix

Automatically merging release branches

2.1.5-SNAPSHOT2.1.4

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

git merge --strategy= resolve

git merge --strategy= recursive

git merge --strategy=

git merge --strategy= ours

2.2

2.1

Bugfix

Automatically merging release branches

2.1.5-SNAPSHOT2.1.4

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

2.2

2.1

Bugfix

Automatically merging release branches

merge commit, content discarded

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

overall picture

master

2.2

2.1

bugfix

feature-1

feature-2

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:

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

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

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 Continually

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 Continually Never

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 Continually Never

Less stable than its baseline

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 Continually Never

Less stable than its baseline

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 Continually Never

Less stable than its baseline When code complete

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 Continually Never

Less stable than its baseline When code complete Continually

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 Continually Never

Less stable than its baseline When code complete Continually

Release branch

Release branch

Feature branchesCredit: Laura Wingerd - The Flow of change

The merge protocolThe secret sauce

Release branch

Release Branch

Master

http://bit.ly/branch-based-workflows

The merge protocolThe secret sauce

Release branch

Release Branch

Master

Merge continually

http://bit.ly/branch-based-workflows

The merge protocolThe secret sauce

Release branch

Release Branch

Master

Merge continually

Never merge!

http://bit.ly/branch-based-workflows

The merge protocolThe secret sauce

Release branch

Release Branch

Master

Merge continually

Backport single changes using git cherry-pick

Never merge!

http://bit.ly/branch-based-workflows

http://bit.ly/branch-based-workflows

The merge protocolThe secret sauce

atlassian.com/gitMore on git workflows

Practices

Practices4

What happens to CI with git?

experiment on your feature branch

Running builds on feature branches

experiment on your feature branch

Running builds on feature branches

experiment on your feature branch

Running builds on feature branches

experiment on your feature branch

Running builds on feature branches

keep your master branch green

x developer

x developer

times

x push to remote

x developer

times

x push to remote

=lots of builds (waiting)

Running builds on feature branches

automatically

manuallyfeature/IRKD-30

master

v 1.2

Code Reviews

Code ReviewsBetter Quality

Learn

Find errors

Pull Requestspart of your daily workflow

Part of your daily work

Part of your daily work

Pull Request

Discuss

Part of your daily work

Pull Request

Discuss

In Conclusion: the recipe

!!!

Branching Model

Adopt Git Practices

!!!!!

!!!

Collaboration Model

!!!

Branching Model

Adopt Git Practices

!!!!!

!!!

Collaboration Model

Centralized

!!!

Branching Model

Adopt Git Practices

!!!!!

Productworkflow

!!!

Collaboration Model

Centralized

!!!

Branching Model

Adopt Git Practices

!!!!!

Productworkflow

Continuousdeliveryworkflow

!!!

Collaboration Model

Centralized

!!!

Branching Model

Adopt Git Practices

!!!!!

Productworkflow

Continuousdeliveryworkflow

!!!

Collaboration Model

Centralized

Mergeprotocol

!!!

Branching Model

Adopt Git Practices

!!!!!

Productworkflow

Continuousdeliveryworkflow

Buildautomatically,

but leaveknobs!

!!!

Collaboration Model

Centralized

Mergeprotocol

!!!

Branching Model

Adopt Git Practices

!!!!!

Productworkflow

Continuousdeliveryworkflow

Embrace PR

Buildautomatically,

but leaveknobs!

!!!

Collaboration Model

Centralized

Mergeprotocol

!!Thank you for your !attention! !!!!

@stefansaasen !!

[email protected] !

www.atlassian.com

http://www.flickr.com/photos/45143319@N00/3888895871/

http://www.flickr.com/photos/40145521@N00/460270581/

http://www.flickr.com/photos/41864721@N00/4647696349

http://www.flickr.com/photos48889052497@N01/12613483263/

http://www.flickr.com/photos/30928442@N08/4766664095/

http://www.flickr.com/photos/marfis75/3272079115/

Credits