Getting gitty With It

Effective git Workflows

Liran Tal

codecamp 2017

Liran Tal

Engineering Manager at Nielsen

Node.js, Security, and Open Source evangelist

"ask 10 developers for the best git workflow,
and you get 12 solutions"

 

made up quote by me

Git Flow

GitHub Flow

Trunk Based Development

One Size
Does Not Fit All

Can't find a buggy commit?

Have 1000 floating branches?

Git history looks like garbage?

Unfortunately, 

 

you're diagnosed with AGD

Acute Git Disorder (AGD)

source: http://blogs.perl.org/users/graham_knop/

Branching Strategy

Branching Strategy

satisfy the customer through early and continuous delivery

Branching Strategy

Simplicity--the art of maximizing the amount of work not done--is essential

Branching Strategy

  • Single Repository

    • Manage per-user access-control

    • Many dangling & long-lived branches

  • Suits traditional product release cycles 

source: https://github.com/facebook/react-devtools

Can you read the graph?

Merge Strategy

Merge Strategy

source: https://twitter.com/HenryHoffman/status/694184106440200192

  • Merge-Commits

    • Preserve ancestry

    • Represent every single change on the branch

    • Group commits

    • Simple workflow

    • Clutter the git history
       

  • "When the Intern is still learning git" - Reddit post

source: https://www.reddit.com/r/ProgrammerHumor/comments/4eflwl/when_the_intern_is_still_learning_git/

Merge Strategy

when did you last
code review
commit by commit ?

" I pulled master,
I pulled master,

commit bugfix,

apologies for the git disaster"
 

made up poem by me

Simple Workflow,
Inconsistent Merge Strategy

Merge Strategy

git merge <feature_branch>

sometimes leads to fast-forward

Merge Strategy

What happens if you

git reset HEAD~

it's a tricky question because we're using a tricky merge strategy

Why does this not happen with rebase?

What happens if you
revert the merge?

Lack of Standardization

  • Commit Messages

     

    • No standards

    • No scoping

    • Doesn't convey the intent of change
       

  • Is each commit testable?

source: https://github.com/google/guava/

When you find a bug in production the one thing you don't have is time

  • Short Lived Branches

  • Integrating Code Frequently

  • Fix-Forward / Release Branches

  • Branch By Abstraction

  • Enabler for CI/CD

  • Short Lived Branches

  • Integrating Code Frequently

  • Fix-Forward / Release Branches

  • Branch By Abstraction

  • Enabler for CI/CD

Branch By Abstraction

"Branch by Abstraction" is a technique for making a large-scale change to a software system in gradual way that allows you to release the system regularly while the change is still in-progress.

source: https://martinfowler.com/bliki/BranchByAbstraction.html

source: https://martinfowler.com/bliki/BranchByAbstraction.html

  • You can't always swap out one consumer and it's an all-or-nothing
     

  • Consider breaking supplier to sub-components

These companies
are doing TBD

practicing TBD

15,000 Developers

4000+ Active Project

20+ Code changes a min

75+ Million test cases per day

A Suggested Workflow

Forking Strategy

  • Distributed collaboration model

    • Governance & Cross-team collaboration

  • Keep upstream repo "in shape"

  • Foster for Open Source activism

Pull Requests 

  • Empower and Recognise Contributors

Pull Requests 

  • Empower and Recognise Contributors

Pull Requests 

  • Empower and Recognise Contributors

Pull Requests 

  • Empower and Recognise Contributors

Pull Requests 

  • Empower and Recognise Contributors

Pull Requests 

  • Foster Code Review

Pull Requests 

  • Increase Developer Confidence:

    • Builds, Static Analysis, Code Quality, SecOps

Pull Requests 

Template-based issues

.github/PULL_REQUEST_TEMPLATE.md
# Summary


## Proposed Changes

  -
  -

## Checklist

- [ ] I added tests
- [ ] I updated the README if necessary
- [ ] This PR introduces a breaking change
- [ ] Fixed issue #
- [ ] I added a picture of a cute animal cause it's fun

Pull Requests 

Template-based issues

.github/PULL_REQUEST_TEMPLATE.md

Pull Requests 

  • Auto-assign team members
     
  • Enforce merge strategy
    • Merge Commit
    • Squash Merge
    • Rebase
       
  • Enforce merge conditions
    • Reviewer approved
    • All GitHub integrations pass

How code makes it to master?

Reb___

Rebase/Squash Strategy

Rebase/Squash Strategy

source: https://gist.github.com/leesmith/8441773

Rebase/Squash Strategy

source: https://developer.atlassian.com/blog/2014/12/pull-request-merge-strategies-the-great-debate/

Rebase/Squash Strategy

  • Linear history vs branch merges
    • Every single commit is tested and deployable

    • Linear sequence of changes through-time

    • Makes it easy to git bisect

Rebase/Squash Strategy

Rebase/Squash Strategy

  • Rebase + Squash
    • A change is introduced as one commit

    • History remains as part of PR + Branch
      in Downstream repo
       

  • Rebase your own work, not public work

  • With rebase commits are ordered when you insert
    them, not when you create them.

"Git is an editor.
“Firmly against rebase” is like being firmly against backspace
"

isaacs (@izs)

Standardization

  • Commit Messages
    • Standards for
      fix, chore, feat, test
       

    • Scoped areas of change
       

  • Employ Commitizen

source: https://github.com/angular/angular.js

the flow

Effective git Workflows

Upstream

Origin

Fork

$ git clone git@github.com/<origin>
$ git remote add upstream git@github.com/<upstream>

Effective git Workflows

Upstream

Origin

on branch master
$ git checkout -b feat/sync-export-btn
$ git add .
$ yarn run commit
$ git push origin HEAD

New
Branch

feat/xyz

Effective git Workflows

Upstream

Origin

feat/xyz

Create
PR

Effective git Workflows

Upstream

Origin

feat/xyz

Sync
w/ master

on branch feat/sync-export-btn
$ git checkout master
$ git fetch upstream
$ git rebase upstream/master
$ git checkout feat/sync-export-btn
on branch feat/sync-export-btn
$ git rebase upstream/master

Effective git Workflows

Upstream

Origin

feat/xyz

Update
PR

on branch feat/sync-export-btn
$ git push origin HEAD --force

Effective git Workflows

Upstream

Origin

feat/xyz

Merge
PR

secret sauce

Effective git Workflows

Fork & Pull-Request

secret sauce

Effective git Workflows

Fork & Pull-Request

Linear git history

secret sauce

Effective git Workflows

Fork & Pull-Request

Linear git history

Standardize 

multumesc

Don't be shy to reach out to me!

Effective Git Workflows

By Liran Tal

Effective Git Workflows

Git is wonderful in it’s flexibility but not all workflows created equal. There’s a good chance your workflow could be optimized and scaled well as your team and org grows. In this talk I will share how the processes, workflows and standards that we employ at Nielsen’s Marketing Cloud enable us to adapt a CI/CD culture, take control again on our git history and foster collaboration and confidence throughout the organization.

  • 2,426