Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git Branching for Success and Profit

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

More Decks by Lorna Mitchell

Other Decks in Technology


  1. 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.
  2. Git Branch We create a branch and keep committing: git

    branch feature and git checkout feature git checkout -b feature
  3. Git Merge The plan: • Check out the branch that

    changes should arrive into. • Merge. git checkout master git merge feature
  4. 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)
  5. Undo an Old Merge Use git revert but specify which

    way you want to go at the fork git revert -m 1 d1151
  6. 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
  7. 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.
  8. 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
  9. 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
  10. Git Flow Comprehensive branching strategy, supported by scripts. • Article:

    http://lrnja.net/1ebawKU • Scripts: https://github.com/nvie/gitflow
  11. Other Branching Strategies • GitHub Flow: http://lrnja.net/1Gr29Jn • Atlassian blog:

    http://lrnja.net/1BSFQcQ • Docs from GitLab: http://lrnja.net/1AiPxQJ Some common elements can be spotted throughout
  12. 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
  13. Environment Branches Maintain one branch per platform • branch always

    reflects current state of platform • plays well with automated deployment
  14. 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
  15. Feedback (and Resources) • How was it? https://m.joind.in/talk/50bd3 • Links

    bundle: http://lrnja.net/135jCIy • My git book: http://gitworkbook.com/ See Also: • Matthew's Scripts: http://lrnja.net/1AiQrgh