git branching for agile teams jda edit · merge up when work is done feature/dev-30 master with...

93
Git Branching for Agile Teams

Upload: others

Post on 25-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Git Branching for Agile Teams

Page 2: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Why use Git + agile?

Page 3: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Git helps agile teams unleash their potential

Page 4: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Developer

How?

Page 5: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

First, let’s review two pillars of agile

Page 6: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

1

Build in narrow vertical slices

Page 7: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Waterfall: can’t release anything until everything is ready to release

DATA BA S E

BAC K E N D

F R O N T E N D

T E S T I N G

“big bang” launch

Page 8: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

DATA BA S E

BAC K E N D

F R O N T E N D

T E S T I N G

MVP launch

Agile: something can get released fairly quickly

Page 9: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Modularity for the win!

Page 10: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Or to put it another way…Potentially shippable, even without this piece

I have a roof!

Page 11: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

The modular house may not have all its

components, but it’ll be move-in ready first

Page 12: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Modularity enables teams to have something testable

—and potentially shippable— much sooner

Page 13: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

2

Make releases a non-event

Page 14: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

A big bang style release (everything at once)

means dependencies up the wazoo

Page 15: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Look familiar?

Just a few dependencies...

Page 16: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Do you hold everything in a local workspace until the entire user

story is implemented?

Page 18: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

That would mean an important practice for agile

teams wasn’t followed: continuous integration

Page 19: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Continuous integration, noun: Testing changes against the existing code base and in-progress changes from the team throughout the development cycle.

Page 20: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Sure CI is important, but…

Page 21: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Will frequent, incremental changes to the repo introduce

more risk?

Page 23: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

But only if all those changes are piled on the primary code line

Page 24: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

The idea is to push changes to the repo without de-stabilizing the primary code line

Page 25: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

That’s where Git comes in

Page 26: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Tell me more!

Developer

Page 27: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

branching & merging is hell

In Subversion

Page 28: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

branching & merging is easy

In Git

Page 29: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

It’s all in the way data and histories

are tracked

Page 30: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Git stores data as a series of snapshots

(rather than changesets)

Page 31: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

If SVN is a hand-drawn map,

Git comes with built-in GPS

Page 32: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Git uses triangulation to figure out what the

merged version should look like on its own

Page 33: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

But enough about the technical

underpinnings

Page 34: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Git enables a dev to fully exploit the power of branch-and-merge

workflows

Page 35: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Why use a branching workflow?

Page 36: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Branching protects the main code line, and

supports an individual developer’s workflow

Page 37: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Atlassian devs create a branch for each

issue they work on

Page 38: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

And it’s helping us deliver faster than

ever before

Page 39: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Keep the main line clean

Dev branches are like an isolation

chamber

Page 40: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

No half-baked code on the main line

Page 41: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

There are other benefits, too…

Page 42: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Clarity & traceability

If it’s been merged up, it’s ready to release. Easy!

Page 43: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

The branch-per-issue model is the synthesis of:

“build in narrow vertical slices” +

“make releases a non-event”

Page 44: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Branch-per-Issue Workflow

for SaaS teams

Page 45: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

The basic idea: a master code line with several

development branches running alongside it

Page 46: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

A branch for every issueKeep master green

feature/DEV-30

feature/DEV-45

master

Experiment on your feature branch

Page 47: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Creating a branch

feature/DEV-30

master

Check your CI system to make sure you’re creating your dev branch from a clean commit!

Page 48: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Break all the tests on a branch without

disrupting teammates

Page 49: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Merge up when work is done

feature/DEV-30

master

With implementation complete, and CI passing, merge upstream! On some teams, the product owner acts as a “gatekeeper,” selecting branches for merge based on what they want to release.

Page 50: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

The beauty of this branching model:

Page 51: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Code changes that are breaking tests on a dev branch

aren’t affecting master or impeding the team’s ability to

release from master

Page 52: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

It’s easy to control what is released to users and

what is held back

Page 53: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Now, a variation on that model:

Page 54: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Using an Integration Branch

Page 55: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

The basic idea: a shared integration branch running between feature branches

and the master branch

Page 56: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

But what if teammates merge incompatible changes upstream?

Page 57: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Surprise!

feature/DEV-30

feature/DEV-45

master

Page 58: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Now master is broken

Page 59: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

And that’s sad

Page 60: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Some teams avoid this by using a shared branch

to integrate changes during development

Page 61: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Builds fail on the integration branch,

not the release branch

Page 62: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Using an integration branch

integration

feature/DEV-30

master

feature/DEV-45

Page 63: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Merge all clean CI runs on the dev branch to the integration branch and run CI

Page 64: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

If changes don’t play well with changes made by teammates, go back

and fix the branch

Page 65: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

When implementation is done and CI on the

integration branch is clean, it’s ready to merge to master

Page 66: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Branch-per-Issue Workflow

for installed app teams

Page 67: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Multiple-version support

master

v 1.2

v 1.1

feature/DEV-30

Page 68: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

In this model, master acts as an

“alpha” branch

Page 69: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Devs make branches off of master for

new development

Page 70: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

And run CI, maybe use an integration

branch, etc.

Page 71: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Then a stable version branch is cut just

before release time

Page 72: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Create a bugfix branch off the release branch

and fix the problem there

Page 73: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Multiple-version support

master

v 1.2

bugfix-DEV 32

feature/DEV-30

Page 74: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Then cascade the fix back to the stable version

branch and master

Page 75: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Incorporating Agile Best Practices

Page 76: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Continuous Integration & Peer Review

Page 77: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Running CI on dev branches

All active branches are under test

Page 78: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Yes: all active branches

Page 79: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

But that can clog the

build queue

Zzzz

Page 80: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Balance testing rigor and resource conservation

with manually triggered builds on dev branches

Page 81: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Triggering CI

master

v 1.2

feature/DEV-30

Developer

Automation

Page 82: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

What about code reviews?

Page 83: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

With Git, use pull requests to integrate

peer review into the workflow

Page 84: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Using pull requests1

2

3

Create request via UI or git request-pull

Review, revise, rinse & repeat

Approve & merge

Page 85: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Additional Considerations

Page 86: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Is “pure” continuous integration in a

branch-per-issue model possible?

Page 88: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

For a CI purist, that matters

!

For a CI pragmatist, it doesn’t

Page 89: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

But shared integration branches and pulling updates from master

down to dev branches comes close to “pure”

Page 90: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

And this workflow is so powerful for agile teams, it’s

wise to be practical

Page 91: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

Here’s to easy releases, happy developers, and

getting Git right!

Page 92: Git Branching for Agile Teams jda EDIT · Merge up when work is done feature/DEV-30 master With implementation complete, and CI passing, merge upstream! On some teams, the product

More info

1 http://atlassian.com/git

2 @Atlassian