Real World Git Workflows - EclipseCon Europe 2013

1,450 views

Published on

While Git is established in the Open Source world, we're only just seeing the emergence of DVCS in our daily jobs. How can DVCS enable us to collaborate in a traditional "enterprise" setting.

Atlassian has fully embraced DVCS and has started to build features into their suite of products to take advantage of this new and exciting paradigm.

The talk will dive deep into the successful git work flows used inside Atlassian. There is no size fit all for this topic and various effective processes can be devised and are in active used at our company.

The talk will also cover tools and techniques used to reduce friction during the development of features and bugfix releases like for example pre/post receive hooks and automatic merges.

Outline:

* Software Development Practices And DVCS
- Branch vs fork (single server/repo, vs forks)
- Code quality (pre-commit hook, pre-checkout hook, pre-receive, see below)
* Awesome Git Workflows Used Internally At Atlassian
- Continuous Delivery Branching model
- Product Releases Branching model
* Streamlining Your Git Process
- merge vs rebase
- Rebase as cleanup
- Meaningful merges
- hooks
. hooks in general
. Post-checkout checks
. pre-commit hooks
. Great Pre-receive and Post-receive hooks
- Automatic merges
* How does CI change when you move to git?

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,450
On SlideShare
0
From Embeds
0
Number of Embeds
151
Actions
Shares
0
Downloads
59
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Real World Git Workflows - EclipseCon Europe 2013

  1. 1. Real World Workflows
  2. 2. Nicola Paolucci Developer Advocate / Git Evangelist I come out nice in pictures, I know :-). durdn.com @durdn
  3. 3. You heard has Cheap local branching Full local history 10x the speed of svn Staging area Speed Huge community Feature based workflow prominent in Open Source cryptographic integrity Distributed
  4. 4. ground breaking paradigm is ground breaking
  5. 5. Workflow building blocks fork cheap branching rebase powerful merging distributed clone
  6. 6. Can we do a fast Can we fix a bug for the upcoming RELEASE HOTFIXrelease? for the current ? Can we BUILD the current code ? Is the code for that FEATURE complete? Has everybody REVIEWED ? the code for this feature
  7. 7. What we’ll cover:
  8. 8. What we’ll cover: 1 Branching models
  9. 9. What we’ll cover: 1 Branching models 2 Practices & Decisions
  10. 10. What we’ll cover: 1 Branching models 2 Practices & Decisions 3 Tooling & Automation
  11. 11. What we’ll cover: 1 Branching models 2 Practices & Decisions 3 Tooling & Automation 4 Continuous Integration
  12. 12. Which branching model?
  13. 13. 1 Which branching model?
  14. 14. Two common Branching Models
  15. 15. Two common Branching Models 1 Continuous Delivery
  16. 16. Two common Branching Models 1 Continuous Delivery 2 Product Releases
  17. 17. for Continuous Delivery
  18. 18. 1.1 for Continuous Delivery
  19. 19. Time feature staging master/ production
  20. 20. staging Time feature master/ production master is in production
  21. 21. staging Time feature master/ production master is in production staging is the next version
  22. 22. staging Time feature master/ production master is in production staging is the next version new features off staging with branch names like: username/ISSUE-KEY-summary
  23. 23. staging Time feature master/ production master is in production PR staging is the next version new features off staging with branch names like: username/ISSUE-KEY-summary
  24. 24. staging promoted from staging, can receive hotfixes Time feature master/ production master is in production PR staging is the next version new features off staging with branch names like: username/ISSUE-KEY-summary
  25. 25. staging promoted from staging, can receive hotfixes Time feature master/ production master is in production PR staging is the next version new features off staging with branch names like: Hotfix username/ISSUE-KEY-summary
  26. 26. staging promoted from staging, can receive hotfixes Time feature master/ production master is in production PR staging is the next version new features off staging with branch names like: Hotfix username/ISSUE-KEY-summary
  27. 27. for Product Releases
  28. 28. 1.2 for Product Releases
  29. 29. 1 One Central Repository
  30. 30. master PRJ-123-description Time feature branches 1 One Central Repository 2 One Branch per Feature
  31. 31. PRJ-123-bug-description Time bugfix branch master 1 One Central Repository 2 One Branch per Feature 3 One Branch per Bugfix
  32. 32. 2.2 PRJ-345-bug-description Time bugfix release branch master
  33. 33. master 2.2 PRJ-345-bug-description Time bugfix release branch 4 Release Branches
  34. 34. master Long running 2.2 PRJ-345-bug-description Time bugfix release branch 4 Release Branches
  35. 35. master Long running 2.2 PRJ-345-bug-description Time bugfix release branch 4 Release Branches 5 master is alpha / RC
  36. 36. Automatic merges for the win!
  37. 37. release branch release branch 2.1 2.2 PRJ-345-bug-description Time bugfix master
  38. 38. Automatic MERGES! release branch release branch 2.1 2.2 PRJ-345-bug-description Time bugfix master
  39. 39. Automatic MERGES! release branch release branch 2.1 2.2 PRJ-345-bug-description Time bugfix master
  40. 40. Automatic MERGES! release branch release branch 2.1 2.2 PRJ-345-bug-description Time bugfix master
  41. 41. Placeholder for changes you DON’T want to merge!
  42. 42. release branch release branch 2.1 2.2 2.2.1
  43. 43. release branch release branch 2.1 2.2 2.2.1 2.1.4
  44. 44. release branch release branch 2.1 2.2 2.2.1 2.1.4 2.1.5-SNAPSHOT
  45. 45. release branch release branch 2.1 2.2 2.2.1 2.1.4 2.1.5-SNAPSHOT We don’t want to merge the 2.1.x version!
  46. 46. release branch release branch 2.1 2.2 2.2.1 2.1.4 2.1.5-SNAPSHOT What can we do here? We don’t want to merge the 2.1.x version!
  47. 47. git merge
  48. 48. git merge --strategy= resolve
  49. 49. git merge --strategy= recursive
  50. 50. git merge --strategy=
  51. 51. git merge --strategy= ours
  52. 52. stable branch stable branch 2.1 2.2 2.2.1 2.1.4 2.1.5-SNAPSHOT
  53. 53. stable branch stable branch 2.1 2.2 2.2.1 2.1.4 2.1.5-SNAPSHOT $> git checkout stable-2.2 $> git merge -s ours stable-2.1
  54. 54. stable branch stable branch 2.1 2.2 2.2.1 2.1.4 2.1.5-SNAPSHOT $> git checkout stable-2.2 $> git merge -s ours stable-2.1 merge commit, content discarded
  55. 55. Deep breath, it’s really simple
  56. 56. The secret sauce The merge protocol
  57. 57. The secret sauce The merge protocol 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
  58. 58. The secret sauce The merge protocol 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
  59. 59. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline
  60. 60. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline
  61. 61. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline
  62. 62. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline
  63. 63. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline Feature branches
  64. 64. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline Feature branches
  65. 65. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline Feature branches
  66. 66. The secret sauce The merge protocol When a branch is: Change flows from branch to baseline: Change flows from baseline to branch: More stable than its baseline Continuously Never When code complete Continuously Release branch Less stable than its baseline Feature branches Credit: Laura Wingerd - The Flow of change
  67. 67. The secret sauce The merge protocol Release Branch Master
  68. 68. The secret sauce The merge protocol Release Branch Merge continuously Master
  69. 69. The secret sauce The merge protocol Release Branch Never Merge merge! continuously Master
  70. 70. The secret sauce The merge protocol Release Branch Never Merge merge! continuously Master Backport single changes using git cherry-pick
  71. 71. Practices & Decisions
  72. 72. turbo boost! 2 Practices & Decisions
  73. 73. What is a Pull Request?
  74. 74. Pull Request I have some code here! Hey I have some code I want to merge here, take a look? Low friction collaboration Can I merge it here?
  75. 75. Merge vs Rebase Does a debate even exist? REBASE MERGE
  76. 76. What is a Rebase? feature master
  77. 77. What is a Rebase? Merge commit feature master
  78. 78. What is a Rebase? Merge commit feature master feature master
  79. 79. What is a Rebase? Merge commit feature master feature master
  80. 80. What is a Rebase? Merge commit feature master feature master
  81. 81. What is a Rebase? Merge commit feature master feature master
  82. 82. Merge as team policy
  83. 83. Merge as team policy 1 Traceability
  84. 84. Merge as team policy 1 Traceability 2 At a cost: readability
  85. 85. Merge as team policy 1 Traceability 2 At a cost: readability 3 bisect debugging is harder
  86. 86. Merge as team policy with no fast-forwards 1 Traceability 2 At a cost: readability 3 bisect debugging is harder
  87. 87. Rebase as team policy [1]
  88. 88. Rebase as team policy [1] 1 History flat and clean
  89. 89. Rebase as team policy [1] 1 History flat and clean 2 Delicate with Pull Requests
  90. 90. Rebase as team policy [1] 1 History flat and clean 2 Delicate with Pull Requests 3 Dangerous for unexperienced
  91. 91. Rebase as team policy [2]
  92. 92. Rebase as team policy [2] 4 Re-resolve similar conflicts
  93. 93. Rebase as team policy [2] 4 Re-resolve similar conflicts 5 Requires often a force push
  94. 94. Rebase as team policy [2] 4 Re-resolve similar conflicts 5 Requires often a force push 6 Loses context for feature
  95. 95. Rebase as a local cleanup
  96. 96. Rebase as a local cleanup 1 Do it
  97. 97. Rebase as a local cleanup git rebase --interactive 1 Do it
  98. 98. Rebase as a local cleanup git rebase --interactive 1 Do it 2 Do it
  99. 99. Rebase as a local cleanup git rebase --interactive 1 Do it 2 Do it 3 Do it!!!!!!
  100. 100. Recommendation?
  101. 101. Recommendation? 1 If team unfamiliar, don’t rebase
  102. 102. Recommendation? 1 If team unfamiliar, don’t rebase 2 Encourage rebase as cleanup and proper ecology
  103. 103. Recommendation? 1 If team unfamiliar, don’t rebase 2 Encourage rebase as cleanup and proper ecology 3 Choose clean or traceable
  104. 104. Recommendation?
  105. 105. Recommendation? 4 Don’t fear the Merge! Use it!
  106. 106. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it!
  107. 107. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it! git log --first-parent
  108. 108. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it! git log --first-parent 5 May rebase feature branches
  109. 109. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it! git log --first-parent 5 May rebase feature branches To update the feature branch
  110. 110. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it! git log --first-parent After review! 5 May rebase feature branches To update the feature branch
  111. 111. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it! git log --first-parent After review! 5 May rebase feature branches To update the feature branch 6 Work with the tool!
  112. 112. Recommendation? Explicit merges into the mainline 4 Don’t fear the Merge! Use it! git log --first-parent After review! 5 May rebase feature branches To update the feature branch 6 Work with the tool! Trying to strive for a linearized history is less useful than you think
  113. 113. Single Repository vs Remote Forks
  114. 114. With Forks Every one has their remote repository
  115. 115. With Forks Every one has their remote repository Full remote copy, each has one Integrator, Gatekeeper, Tech Lead, etc.
  116. 116. Pros of a Single Repo
  117. 117. Pros of a Single Repo 1 Complete visibility
  118. 118. Pros of a Single Repo All feature branches available 1 Complete visibility
  119. 119. Pros of a Single Repo All feature branches available 1 Complete visibility 2 No per Dev remotes required
  120. 120. Pros of a Single Repo All feature branches available 1 Complete visibility 2 No per Dev remotes required 3 KISS
  121. 121. Forks Are Great too BTW
  122. 122. FORKING IN THE ENTERPRISE
  123. 123. FORKING IN 5 Reasons for... ENTERPRISE
  124. 124. FORKING IN ENTERPRISE REASON 1 Great for customizing libraries
  125. 125. FORKING IN ENTERPRISE REASON 1 Great for customizing libraries and still get bug fixes
  126. 126. FORKING IN ENTERPRISE REASON 2 Great for innovation spikes
  127. 127. FORKING IN ENTERPRISE REASON 2 Great for innovation spikes and maybe add it later
  128. 128. FORKING IN ENTERPRISE REASON 3 Protecting your components
  129. 129. FORKING IN but still be open for changes REASON 3 Protecting your components ENTERPRISE
  130. 130. FORKING IN ENTERPRISE REASON 4 Reduce the noise
  131. 131. FORKING IN ENTERPRISE REASON 4 Reduce the noise and keep the overview for huge projects
  132. 132. FORKING IN ENTERPRISE REASON 5 Interaction with Contractors & Interns
  133. 133. FORKING IN ENTERPRISE REASON 5 Interaction with Contractors & Interns protect your sources
  134. 134. Tooling & Automation
  135. 135. 3 Tooling & Automation
  136. 136. Hooks
  137. 137. “ Hooks are little scripts you can place in the `$GIT_DIR/hooks` directory to trigger ” action at certain points. – githooks Documentation
  138. 138. Pre Post
  139. 139. Local Remote
  140. 140. Local pre-/post-applypatch pre-/post-commit Remote pre-receive update pre-rebase post-receive post-checkout post-update post-merge pre-push
  141. 141. Code Quality via pre-commit hooks
  142. 142. .git/hooks/pre-commit
  143. 143. git add -u git commit -m "TEST checkstyle"
  144. 144. Starting audit... /Users/user/[...]/com/atlassian/stash/ web/projects/ProjectController.java: 161:12: 'for' is not followed by whitespace. Audit done. Commit aborted.
  145. 145. Branch from green builds
  146. 146. .git/hooks/post-checkout
  147. 147. $ 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.
  148. 148. Get it at: bitly.com/green-builds
  149. 149. What happens to CI with ?
  150. 150. 4 What happens to CI with ?
  151. 151. 1 What happens to CI with git?
  152. 152. 1 What happens to CI with git? 2 An explosion of branches
  153. 153. 1 What happens to CI with git? 2 An explosion of branches 3 Performance degradation of build sys
  154. 154. 1 Building everything is expensive
  155. 155. 1 Building everything is expensive 2 Automatically build stable and master
  156. 156. 1 Building everything is expensive 2 Automatically build stable and master 3 Manually trigger feature branch builds
  157. 157. In Conclusion: the recipe
  158. 158. Conclusions Collaboration Model Branching Model Practices & Decisions Automation & CI setup
  159. 159. Conclusions Collaboration Model Centralized Branching Model Practices & Decisions Automation & CI setup
  160. 160. Conclusions Collaboration Model Branching Model Product workflow Centralized Practices & Decisions Automation & CI setup
  161. 161. Conclusions Collaboration Model Branching Model Product workflow Centralized Continuous delivery workflow Practices & Decisions Automation & CI setup
  162. 162. Conclusions Collaboration Model Branching Model Product workflow Centralized Continuous delivery workflow Practices & Decisions Embrace PR Automation & CI setup
  163. 163. Conclusions Collaboration Model Branching Model Product workflow Practices & Decisions Embrace PR Merge vs Centralized Continuous delivery workflow Rebase Automation & CI setup
  164. 164. Conclusions Collaboration Model Branching Model Product workflow Practices & Decisions Embrace PR Merge vs Centralized Continuous Rebase delivery workflow Single Repo or Forks Automation & CI setup
  165. 165. Conclusions Collaboration Model Branching Model Product workflow Practices & Decisions Embrace PR Merge vs Centralized Continuous Rebase delivery workflow Single Repo or Forks Automation & CI setup Hooks, hooks everywhere
  166. 166. Conclusions Collaboration Model Branching Model Product workflow Practices & Decisions Embrace PR Merge vs Centralized Continuous Rebase delivery workflow Single Repo or Forks Automation & CI setup Hooks, hooks everywhere Build automatically, but leave knobs!
  167. 167. Nicola Paolucci THANK YOU FOR YOUR ATTENTION! Should I change the pic? ;-) durdn.com @durdn
  168. 168. Atlassian Git Repository Management for Enterprise Teams Free Git Code Hosting for Small Teams Free Git Desktop client for Mac or Windows

×