75
Real World Workflows Stefan Saasen

JAZOON'13 - Stefan Saasen - Real World Git Workflows

Embed Size (px)

Citation preview

Page 1: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Real World WorkflowsStefan Saasen

Page 2: JAZOON'13 - Stefan Saasen - Real World Git Workflows

TODO Show of hands

Picture with hands/lighter/concert

Page 3: JAZOON'13 - Stefan Saasen - Real World Git Workflows

git

Page 4: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Subversion

Page 5: JAZOON'13 - Stefan Saasen - Real World Git Workflows

NO VCSAT ALL?

you must love pain

Page 6: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Stefan SaasenAtlassian Stash Development Lead

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

Page 7: JAZOON'13 - Stefan Saasen - Real World Git Workflows

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

Page 8: JAZOON'13 - Stefan Saasen - Real World Git Workflows

ground breaking paradigm is ground breaking

Page 9: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Workflow building blocks

rebasepowerful merging

fork

efficient clone

cheap branching

distributed

Page 10: JAZOON'13 - Stefan Saasen - Real World Git Workflows

RELEASECan we fix a bug for a

specific?

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?

Page 11: JAZOON'13 - Stefan Saasen - Real World Git Workflows

DIFFERENTPEOPLEPRODUCTSCULTURES

Page 12: JAZOON'13 - Stefan Saasen - Real World Git Workflows

DIFFERENTPEOPLEPRODUCTSCULTURES

Page 13: JAZOON'13 - Stefan Saasen - Real World Git Workflows

DIFFERENTPEOPLEPRODUCTSCULTURES Stash, Bitbucket, JIRA

Page 14: JAZOON'13 - Stefan Saasen - Real World Git Workflows

DIFFERENTPEOPLEPRODUCTSCULTURES

DIFFERENT WORKFLOWS

Page 15: JAZOON'13 - Stefan Saasen - Real World Git Workflows

1

Practices & Decisions

2

3

Collaboration model

We’ll cover:

Branching model

Tooling & Automation4

Page 16: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Which collaboration model?1

Easy, right?

Page 17: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Fully decentralized Anarchy

I do my thingI do my thing, too

ANARCHYhere’s mine, who tells

john?look ma, a goat!

Page 18: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Blessed repository with Gatekeeper

He is cool

Gatekeeper

To have your work accepted, talk to him

Page 19: JAZOON'13 - Stefan Saasen - Real World Git Workflows

and LieutenantsDictator

long live the King!

Lieutenants guardthe King

Blessed repository

Page 20: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Shared common repository

we share “everything”

Centralised

Page 21: JAZOON'13 - Stefan Saasen - Real World Git Workflows

atlassian.com/gitMore on Collaboration models

Page 22: JAZOON'13 - Stefan Saasen - Real World Git Workflows

+ = Centralized

Enterprise

Page 23: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Builds

Metrics

Issues

Deployments

They know where the code needs to go!

Page 24: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Which branching model?2

Page 25: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Product Releases

1 Continuous Delivery

2

Two common Branching Models

Page 26: JAZOON'13 - Stefan Saasen - Real World Git Workflows

2.2 for Continuous Delivery

Page 27: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Tim

emaster/

productionstagingfeature

master is in production

staging is the next version

new features o! staging

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

promoted from staging, can receive hotfixes

Hotfix

PR

Page 28: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Significant branches map to a concept in the outside world. It may be a past release, an environment or a role.Those branches are long-running and stable whereas feature branches are short lived and volatile.Me, just making this up. ”

Page 29: JAZOON'13 - Stefan Saasen - Real World Git Workflows

for Product Releases2.1

Page 30: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Central Repository1

One Branch per Feature

One Branch per Bugfix

2

3

Tim

emasterfeature

branches

PRJ-

123-

desc

ript

ion

Tim

emasterbugfix branch

PRJ-

123-

bug-

desc

ript

ion

Short lived

Page 31: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Release Branches4

master is alpha / RC5

Long running

Tim

emasterrelease

branch

PRJ-

345-

bug-

desc

ript

ion

bugfix

2.2

Page 32: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Automatic merges for the win!

Page 33: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Tim

e

release branch master

2.2

release branch

PRJ-

345-

bug-

desc

ript

ion

bugfix

2.1

Automatic MERGES!

Page 34: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Placeholder for changes you DON’T want to merge!

Page 35: JAZOON'13 - Stefan Saasen - Real World Git Workflows

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?

Page 36: JAZOON'13 - Stefan Saasen - Real World Git Workflows

git mergegit merge --strategy= resolve

Page 37: JAZOON'13 - Stefan Saasen - Real World Git Workflows

git merge --strategy=recursive

Page 38: JAZOON'13 - Stefan Saasen - Real World Git Workflows

git merge --strategy= ours

Page 39: JAZOON'13 - Stefan Saasen - Real World Git Workflows

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

Page 40: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Deep breath, it’s really simple

Page 41: JAZOON'13 - Stefan Saasen - Real World Git Workflows

The merge protocolThe secret sauce

Release branch

Page 42: JAZOON'13 - Stefan Saasen - Real World Git Workflows

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

Continually Never

When code complete Continually

Release branch

Release branch

Feature branchesCredit: Laura Wingerd - The Flow of change

Page 43: JAZOON'13 - Stefan Saasen - Real World Git Workflows

The merge protocolThe secret sauce

Release branch

Release Branch

Master

Mergecontinually

Backport single changes using git cherry-pick

Never merge!

Page 44: JAZOON'13 - Stefan Saasen - Real World Git Workflows

3

turbo boost!

Practices

Page 45: JAZOON'13 - Stefan Saasen - Real World Git Workflows

What is a Pull Request?

Page 46: JAZOON'13 - Stefan Saasen - Real World Git Workflows

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?

Page 47: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Single Repositoryvs

Remote Forks

Page 48: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Every one has their remote repository

With Forks

Full remote copy,each has one Integrator, Gatekeeper,

Tech Lead, etc.

Page 49: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Complete visibility1

No per Dev remotes required

KISS

2

3

Pros of a Single RepoAll feature branches available

Page 50: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Forks Are Great too BTW

Page 51: JAZOON'13 - Stefan Saasen - Real World Git Workflows

FORKING IN THE

ENTERPRISE

Page 52: JAZOON'13 - Stefan Saasen - Real World Git Workflows

FORKING IN THE

ENTERPRISE4 Reasons for...

REASON 1

Great for customizing librariesand still get bug fixes

Page 53: JAZOON'13 - Stefan Saasen - Real World Git Workflows

REASON 2

Great for innovation spikesand maybe add it later

FORKING IN THE

ENTERPRISE

Page 54: JAZOON'13 - Stefan Saasen - Real World Git Workflows

REASON 3

Protecting your components

but still be open for changes

FORKING IN THE

ENTERPRISE

Page 55: JAZOON'13 - Stefan Saasen - Real World Git Workflows

REASON 4

Reduce the noise

and keep the overview for huge projects

FORKING IN THE

ENTERPRISE

Page 56: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Tooling & Automation4

Page 57: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Hooks

Page 58: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Hooks are little scripts you can place in

the `$GIT_DIR/hooks` directory to trigger

action at certain points.

– githooks Documentation

”“

Page 59: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Pre Post

Page 60: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Local Remote

Page 61: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Local Remotepre-receiveupdatepost-receivepost-update

pre-/post-applypatchpre-/post-commit

pre-rebasepost-checkout

post-mergepre-push

Page 62: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Code Quality

Page 63: JAZOON'13 - Stefan Saasen - Real World Git Workflows

.git/hooks/pre-commit

Page 64: JAZOON'13 - Stefan Saasen - Real World Git Workflows

git add -ugit commit -m "TEST checkstyle"

Page 65: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Starting audit...

/Users/user/[...]/com/atlassian/stash/web/projects/ProjectController.java:161:12: 'for' is not followed by whitespace.

Audit done.Commit aborted.

Page 66: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Branch from green builds

Page 67: JAZOON'13 - Stefan Saasen - Real World Git Workflows

.git/hooks/post-checkout

Page 68: JAZOON'13 - Stefan Saasen - Real World Git Workflows

$ 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.

Page 69: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Get it at: bitly.com/green-builds

Page 70: JAZOON'13 - Stefan Saasen - Real World Git Workflows

What happens to CI with git?

Page 71: JAZOON'13 - Stefan Saasen - Real World Git Workflows

1 An explosion of branches

2

3

Performance degradation of build sys

Building everything is expensive

Page 72: JAZOON'13 - Stefan Saasen - Real World Git Workflows

Automatically build stable and master1

Manually trigger feature branch builds2

Page 73: JAZOON'13 - Stefan Saasen - Real World Git Workflows

In Conclusion: the recipe

Page 74: JAZOON'13 - Stefan Saasen - Real World Git Workflows

BranchingModel

Adopt GitPractices

Automation & CI setup

Conclusions

Product workflow

Continuous delivery workflow

Embrace PR

Build automatically,

but leave knobs!Single Repo

or Forks

CollaborationModel

Centralized

Hooks, hooks everywhereMerge

protocol