craig berntson chief software gardener mojo software worx branches and merges are bears, oh my!

43
Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Upload: anne-sullivan

Post on 15-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Craig BerntsonChief Software Gardener

Mojo Software Worx

Branches and Merges are Bears, Oh

My!

Page 2: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Ego stuff

• Chief Software GardenerMojo Software WorxSalt Lake City• Organizer, Utah Code Camp• Author, “Continuous Integration in .Net”• Columnist, “.Net Curry” eMagazine• Conference & event speaker• 18 time Microsoft MVP• INETA Community Speaker• ComponentOne Community Influencer

2

Page 3: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

3

Page 4: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

agenda

Version control in general

Avoid branching

Smart branching

Best practices

4

Page 5: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

What do you call it?

VCS

SCC

5

Page 6: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

VCS generationsFi

rst No network

One file at a timeFile locksRCS, SCSS

Seco

nd CentralizedMulti-fileMerge before commitCVS, SVN, TFS, VSS

Third Distributed

Change setsCommit before mergeGit, Mercurial

6

Page 7: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

VCS Types

Centralized• CVS• Subversion• TFS

Distributed• Git• Mercurial• Telelogic

Stream-based• ClearCase• AccuRev

7

Page 8: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Basic goals

• Work simultaneously• Changes don’t conflict• Archive every version of everything

8

Page 9: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Continuous delivery pipeline

Automated Deployment

Manual Testing

Automated Capacity Testing

Automated Acceptance

Testing

Continuous Integration

9

Check into VCS often Every build is a potential Release Candidate Branching is an anti-pattern Lean: Branch is waste

Page 10: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Why care about this?

• Version control is central to the deployment pipeline• Poor version control is a common barrier to fast, low risk releases

10

Page 11: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Why teams branch

Physical• Files• Components• Subsystems

Functional

• Features• Logical changes• Bug fixes• Enhancements• Patches• Releases

11

Page 12: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Why teams branch

Environmental

• Build and runtime environment• Compilers• Windowing systems• Libraries• Hardware• Operating systems

Organizational

• Activities• Tasks• Subprojects• Roles• Groups

12

Page 13: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Why teams branch

Procedural

• Team’s work behavior• Policies• Processes• States

13

Page 14: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

common scenario

14

Page 15: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Common scenario

15

Page 16: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Why is this bad?

Merge at release Is complex

Branching was poorly

planned

Large changes merged

16

• Delayed release• Fewer features• Lower quality

Page 17: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

How do you fix this?

• Avoid branching• Smart branching

17

Page 18: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Avoid branching

Develop on trunk

Hide new functionality

Incremental changes

Branch by abstraction

Components

18

Page 19: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Hide functionality

• Put in new features but make them inaccessible to users• Turn on/off through configuration• Planning and delivery become easier

19

Page 20: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Hide functionality

20

Page 21: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Incremental changes

• When making large changes, it is tempting to branch so developers work faster• Reality is, the bigger the perceived reason to branch, the more you

shouldn’t branch• Break-down major changes into very small parts and implement each

on the trunk

21

Page 22: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Incremental changes

22

Page 23: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by abstraction

1. Create an abstraction over code that needs to be changed2. Refactor code to use abstraction3. Create the new implementation4. Update abstraction to use new code5. Remove old code6. Remove abstraction layer if not needed

23

Page 24: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by abstraction

24

Page 25: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

components

“A component is reusable, replaceable with something else that implements the same API, independently deployable, and encapsulates some coherent set of behaviors and responsibilities of the system”

- Continuous Deployment

25

Page 26: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Why use components

• Part of codebase needs to be deployed separately• Move from monolithic codebase to a core and plugins• Provide an interface to another system• Compile and link cycle are too long• Takes to long to open project in IDE• Codebase is too large for a single team

26

Page 27: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Issues with components

• Components everywhere• God components• Teams are responsible for individual components• Increased dependency management

27

Page 28: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by abstraction

28

Page 29: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

avoid branching

• Develop on trunk• Commit code at least daily• Changes done in small increments• Requires good componentization, incremental changes, feature

hiding• Gives quick feedback on every change

29

Page 30: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

When is branching ok?

• Release a new version of your application• Spike out a new feature or refactoring• Short-lived branch to make large changes that can’t be done with

other methods

30

Page 31: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

When you need to branch

Smart branching

Branch for release

Branch by feature

Branch by team

31

Page 32: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch for release

• Develop on trunk• Branch when code is feature complete• Critical defects are committed on branches, then merged

immediately• Tag the branch when released• Don’t create another branch until after release

32

Page 33: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch for release

33

Page 34: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by feature

• Each user story is a branch• Number of branches = number of stories• After story passes QA, merge into trunk• Trunk changes merge into branches daily• Branches live a few days or less• Refactorings are merged immediately

34

Page 35: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by feature

35

Page 36: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by team

• Merge branches into trunk when stable then immediately into other branches• Teams must be small and independent• Similar to Branch by Feature, but merges more often• CI Problem: Unit of work is scoped to branch, not a single change

36

Page 37: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Branch by team

37

Page 38: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Smart branching

• Branches should be short lived• Merge often• Requires good project management

38

Page 39: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Best practices

• Compare before you commit• Explain commits• Read merge comments from other devs• Keep repositories small• Group commits logically• Only store what’s manually created

39

Page 40: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Best practices

• Don’t break the tree• Use tags• Don’t obliterate• Don’t comment out code• Don’t lock• Build and test before every commit• Build and test after every merge

40

Page 41: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

References

• Continuous Delivery• Jez Humble & David Farley

• Version Control by Example• Eric Sink

• Git• http://pcottle.github.io/learnGitBranching/ • http://git-scm.com/book/en/

• TFS• http://vsarbranchingguide.codeplex.com/

41

Page 42: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Review

Version control in general

• Hide new functionality• Incremental changes• Branch by Abstraction• Components

Avoid branching

• Branch for release• Branch by feature• Branch by team

Smart branching

Best practices

Keep trunk releasable

42

Page 43: Craig Berntson Chief Software Gardener Mojo Software Worx Branches and Merges are Bears, Oh My!

Questions?

[email protected]• www.craigberntson.com/blog• @craigber• youtube.com/watch?v=aX4nf5Co16Q

43