69
Workflows á-la-carte

Git workflows á la-carte, Presenation at jdays2013 by Nicola Paolucci

Embed Size (px)

DESCRIPTION

Git Workflows A-la-carte, Presenation at jdays2013 www.jdays.se by Nicola Paolucci

Citation preview

Page 1: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Workflows á-la-carte

Page 2: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci
Page 3: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Nicola PaolucciDeveloper Advocate / Git Evangelist

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

Page 4: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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

Page 5: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

ground breaking paradigm is ground breaking

Page 6: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Workflow building blocks

rebasepowerful merging

fork

clone

cheap branching

distributed

Page 7: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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?

Page 8: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Practices & Decisions

1

2

What we’ll cover:

Branching models

Tooling & Automation3

4 Continuous Integration

Page 9: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Which branching model?1

Page 10: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Product Releases

1 Continuous Delivery

2

Two common Branching Models

Page 11: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

1.1 for Continuous Delivery

Page 12: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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

Page 13: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

for Product Releases1.2

Page 14: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

One 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

Page 15: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Release Branches4

master is alpha / RC5

Long running

Tim

emasterrelease

branch

PRJ-

345-

bug-

desc

ript

ion

bugfix

2.2

Page 16: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Automatic merges for the win!

Page 17: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

PRJ-

345-

bug-

desc

ript

ion

Tim

e

release branch

master

2.2

release branch

bugfix

2.1

Automatic MERGES!

Page 18: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Placeholder for changes you DON’T want to merge!

Page 19: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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 20: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

git merge --strategy= ours

Page 21: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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 22: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Deep breath, it’s really simple

Page 23: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

The merge protocolThe secret sauce

Release branch

Page 24: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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

Less stable than its baseline When code complete Continuously

Release branch

Release branch

Feature branchesCredit: Laura Wingerd - The Flow of change

Page 25: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

The merge protocolThe secret sauce

Release branch

Release Branch

Master

Merge continuously

Backport single changes using git cherry-pick

Never merge!

Page 26: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Practices & Decisions2

turbo boost!

Page 27: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

What is a Pull Request?

Page 28: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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 29: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Does a debate even exist?

Merge vs Rebase

MER

GE REBA

SE

Page 30: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

master

feature

What is a Rebase?Merge commit

master

feature

Page 31: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Traceability1

At a cost: readability2

3

Merge as team policy

bisect debugging is harder

with no fast-forwards

Page 32: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci
Page 33: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

History flat and clean1

Delicate with Pull Requests

Dangerous for unexperienced

2

3

Rebase as team policy [1]

Page 34: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Re-resolve similar conflicts4

Requires often a force push

Loses context for feature

5

6

Rebase as team policy [2]

Page 35: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Do it1

Do it

Do it!!!!!!

2

3

Rebase as a local cleanup

git rebase --interactive

Page 36: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

If team unfamiliar, don’t rebase1

Encourage rebase as cleanup2

Recommendation?

and proper ecology

Page 37: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Don’t fear the Merge! Use it!3

May rebase feature branches

Work with the tool!

4

5

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!

Page 38: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Single Repository vs

Remote Forks

Page 39: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Every one has their remote repository

With Forks

Full remote copy, each has one Integrator, Gatekeeper,

Tech Lead, etc.

Page 40: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Complete visibility1

No per Dev remotes required

KISS

2

3

Pros of a Single RepoAll feature branches available

Page 41: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Forks Are Great too BTW

Page 42: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

FORKING IN THE

ENTERPRISE

Page 43: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

FORKING IN

ENTERPRISE5 Reasons for...

REASON 1

Great for customizing librariesand still get bug fixes

Page 44: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

REASON 2

Great for innovation spikesand maybe add it later

FORKING IN

ENTERPRISE

Page 45: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

REASON 3

Protecting your components

but still be open for changes

FORKING IN

ENTERPRISE

Page 46: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

REASON 4

Reduce the noise

and keep the overview for huge projects

FORKING IN

ENTERPRISE

Page 47: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

REASON 5

Interaction with Contractors & Interns

protect your sources

FORKING IN

ENTERPRISE

Page 48: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Tooling & Automation3

Page 49: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Hooks

Page 50: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Hooks are little scripts you can place in

the `$GIT_DIR/hooks` directory to trigger

action at certain points.

– githooks Documentation

”“

Page 51: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Pre Post

Page 52: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Local Remote

Page 53: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Local Remotepre-receiveupdatepost-receivepost-update

pre-/post-applypatchpre-/post-commit

pre-rebasepost-checkout

post-mergepre-push

Page 54: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Code Quality via pre-commit hooks

Page 55: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

.git/hooks/pre-commit!

Page 56: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

git add -u!git commit -m "TEST checkstyle"!

Page 57: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Starting audit...!!

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

Audit done.!Commit aborted.

Page 58: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Branch from green builds

Page 59: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

.git/hooks/post-checkout

Page 60: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

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

Page 61: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Get it at: bitly.com/green-builds

Page 62: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

4 What happens to CI with ?

Page 63: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

What happens to CI with git?1

An explosion of branches2

3 Performance degradation of build sys

Page 64: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Building everything is expensive1

Automatically build stable and master2

3 Manually trigger feature branch builds

Page 65: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

In Conclusion: the recipe

Page 66: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

!!!

!!!!!

Branching Model

Practices & Decisions

Automation & CI setup

Conclusions

!!!!!

Product workflow

Continuous delivery workflow

Embrace PR

Build automatically,

but leave knobs!Single Repo

or Forks

!!!

Collaboration Model

Centralized

Hooks, hooks everywhere

Merge vs Rebase

Page 67: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Nicola PaolucciTHANK YOU FOR YOUR ATTENTION!

@durdndurdn.comShould I change the pic? ;-)

Page 68: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

http://strawpoll.me/774809

Page 69: Git workflows á la-carte, Presenation at jdays2013  by Nicola Paolucci

Git Repository Management for Enterprise Teams

Free Git Code Hosting for Small Teams

Free Git Desktop client for Mac or Windows

Atlassian