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

Git Strategies

Git Strategies

An overview on merge and rebase as well as some of the different git workflows a team can adopt based on them. Also goes through some common anti-patterns and how to avoid them.

Avatar for Javier García

Javier García

October 10, 2019
Tweet

More Decks by Javier García

Other Decks in Programming

Transcript

  1. So... why rebase? Modifying broken commits, ergo eliminating bugged commits

    Rearranging content between commits, ergo more meaningful commits Keeping a clean history, ergo... clean history :) 5
  2. How do I rebase? --A---B---C topic / D---E---F---G master $

    git checkout topic $ git rebase master topic --A'--B'--C' topic / D---E---F---G master 6
  3. The powerhouse: interactive rebase The power to rewrite history literally:

    it allows you to alter commits rather than only moving them. It’s based on git commit --amend Interactive mode further allows you to also squash the commits, for a cleaner history. 7
  4. Rebasing caveats Rewrites history – careful with rebasing on public

    branches Merge conflicts are more frequent Commits can be lost in interactive mode 8
  5. What's the difference with rebase? Merge commits are unique against

    other commits in the fact that they have two parent commits. History is completely preserved, instead of rewritting it. 11
  6. Why would I want to merge? Incorporate the commits from

    the named branch into the current branch without loosing history 12
  7. Merging in a nutshell A---B---C topic / D---E---F---G master $

    git checkout master $ git merge topic A---B---C topic / \ D---E---F---G---H master 13
  8. Further details Git merge will combine multiple sequences of commits

    into one unified history. [...] git merge takes two commit pointers, usually the branch tips, and will find a common base commit between them. Once Git finds a common base commit it will create a new "merge commit" that combines the changes of each queued merge commit sequence. If a piece of data that is changed in both histories git will be unable to automatically combine them. Fast-forward vs 3-way merge 14
  9. Trunk-based development Whole team develops to shared branch called trunk

    (!!) Short lived feature branches Release branches When? Just starting up/need quick iterations Mostly senior developers When not? Open source projects Mostly junior developers 16
  10. 17

  11. Gitflow Two main branches: develop and main . Features are

    developed by branching develop and are reviewed before merging. Releases are merges from develop to master . When? The opposite scenarios to Trunk-based development. In other words, any scenario where branch micromanagement could be an asset rather than a burden. 18
  12. 19

  13. And where do merge/rebase fit in? Both of these commands

    are designed to integrate changes from one branch into another branch—they just do it in very different ways. The golden rule of git rebase is to never use it on public branches. Nonetheless, the team decides. 20
  14. Some anti-patterns to be aware of Pushing every commit Can

    you jump to any commit? Long living branches Complicated commit log Using GUIs Commit early, commit often, perfect later, publish once. credits: @lemiorhan 22
  15. Further tools to hone our craft git bisect git log

    git cherry-pick git reflog git hooks 23