Save 37% off PRO during our Black Friday Sale! »

Git Branching for Success and Profit

D33d8bdd9096c80b8d1acca8d28410b5?s=47 Lorna Mitchell
December 19, 2014

Git Branching for Success and Profit

Daycamp for developers, this slide deck accompanied my session at the excellent virtual event that is DC4D.


Lorna Mitchell

December 19, 2014


  1. Git Branching For Success and Profit Lorna Mitchell, Day Camp

    For Developers
  2. Git Branching

  3. A Branch is a Label Take a look in .git/refs/heads/

    • A branch is a pointer to a commit. • You commit on a branch, the commit is created and the pointer updated.
  4. Commits Aren't "On" Branches

  5. Commits Aren't "On" Branches

  6. 11% of branches never get merged

  7. 86% of statistics are made up on the spot

  8. Git Branch We are committing along:

  9. Git Branch We create a branch and keep committing: git

    branch feature and git checkout feature git checkout -b feature
  10. Git Branch Stuff happens on master meanwhile:

  11. Branching is easy. Merging is ?

  12. Branching is easy. Merging is easy when you know how.

  13. Git Merge

  14. Git Merge The plan: • Check out the branch that

    changes should arrive into. • Merge. git checkout master git merge feature
  15. Git Merge

  16. Git Undo

  17. Git Undo How to undo a merge: • Set the

    branch pointer back to where it was before the merge git reset --hard 7e386 (your branch is still intact)
  18. Git Undo

  19. Undo an Old Merge Use git revert but specify which

    way you want to go at the fork git revert -m 1 d1151
  20. Merge Conflicts Merge conflicts occur when git needs some help.


  22. Merge Conflicts: Your Options • git merge --abort • Edit

    the files until things are correct • Use git checkout --[ours|theirs] to get the right version in place Fix the conflict, then add and commit the file(s). Your merge will complete
  23. Merge Types

  24. Fast-Forward Merge No changes on master since we branched

  25. Fast-Forward Merge git merge feature

  26. Force Recursive Merge Start from the same place:

  27. Force Recursive Merge Then merge without fast-forward: git merge --no-ff

  28. Git Rebase

  29. Git Rebase Rebase to move a branch start point

  30. Git Rebase git rebase master We can now fast-forward merge

  31. Rebase Conflicts Rebase applies each of your commits in turn.

    This can result in a conflict at any point. Handle exactly as you would for merge conflicts. Then type git rebase --continue. git rebase --abort is always an option.
  32. Interactive Rebase Rewrite the last N commits. Your options: •

    remove a commit completely • re-order commits • combine commits and/or re-word their commit messages
  33. Branching Strategies

  34. Branching Strategies A branching strategy is basically a git process

    document. It covers: • when to branch • where to branch from • what to call your branch • where to merge to
  35. Git Flow Comprehensive branching strategy, supported by scripts. • Article: • Scripts:
  36. Git Flow

  37. Git Flow

  38. Git Flow

  39. Git Flow

  40. Git Flow

  41. Other Branching Strategies • GitHub Flow: • Atlassian blog: • Docs from GitLab: Some common elements can be spotted throughout
  42. Branching Strategy Ingredients List

  43. Topic Branches Pattern Starting something new? Use a branch.

  44. Topic Branches Pattern Merge from master into feature before merging

  45. Topic Branches Pattern Rebase branch onto master before merging

  46. Master vs Develop This one is a matter of taste!

  47. Hotfix Pattern Branch off, commit once, merge with --no-ff •

    makes it very clear what happened • easily merge the branch back upstream if needed • makes it possible to cleanly undo without losing anything
  48. Hotfix Pattern

  49. Environment Branches Maintain one branch per platform • branch always

    reflects current state of platform • plays well with automated deployment
  50. Environment Branches

  51. Tagging for Releases Git has two types of tags: •

    simple tags are just a label, like a branch that doesn't advance • annotated tags are an object, they can contain messages git tag -a v2.11 -m "v2.11 with caching" Then push the tag
  52. Git Branches

  53. Feedback (and Resources) • How was it? • Links

    bundle: • My git book: See Also: • Matthew's Scripts: