git 201 - a deeper look at git - mdc 2017 · pdf filegit 201 - a deeper look at git git me...

37
GIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler [email protected]

Upload: phungliem

Post on 10-Feb-2018

249 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

GIT 201 - A DEEPER LOOK AT GITGit Me With Your Best Shot

Arthur Doler@[email protected]

Page 2: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

We’ll be using the Gitcommand line…

Source: Giphy

Page 3: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

“FUNDAMENTAL PARTICLES” OF GIT

Page 4: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Blob

artdoler@machine$ git ls-files --stage100644 ac461d89cb0a217c2ee2bfcac33e1c27df7739a7 0 path/to/source/file.js

Page 5: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Tree

artdoler@machine$ git write-treecf09c37fdb1e4ba320d2ae08e9eb32d6913979e3

artdoler@machine$ git ls-tree cf09040000 tree c98ef89a1fc979e593927666c058d15f8111c0bf path

Page 6: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Commit

artdoler@machine$ echo "Manual commit." | git commit-tree cf09c26db2aec27b78aeaed82173ec5f5b2303931b29

artdoler@machine$ git log c26dcommit c26db2aec27b78aeaed82173ec5f5b2303931b29Author: Art Doler [email protected]: Thu May 20 08:59:12 2016 -0500

Manual commit.

Page 7: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

A GIT REPOSITORY

IS JUST GRAPHS OF COMMITS

Page 8: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

What Git Manages For You

What To Actually Think About

Blob

Tree

Commit

Δ

Δ

Δ

Δ

Δ

Δ

Δ

Δ

ΔΔ

ΔΔ

Δ

Page 9: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

HOW DOES GIT MAKE DIFFS?

Page 10: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

B

C

F

E

ACommit 1 Commit 2

Directory Directory

Rename

Delete

EditAdd

Page 11: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

BRANCHES & TAGS

When I realize “DVCS” means I always get my own branch

Source: Giphy

Page 12: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

WHAT’S IN A NAME?

Page 13: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

HEAD

ac461d89cb0a217c2ee2bfcac33e1c27df7739a7

feature/my_feature_branch

^ ~

Page 14: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

B = A^ = A~ = A^1 = A~1

A

B

A = A^0

C

C = B^ = A^^ = A~~ C = A^1^1 = A~2C ≠ A^2

develop

Page 15: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

MERGING

When my coworker’s merge breaks my feature

Source: Giphy

Page 16: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

B = A^ = A~ = A^1 = A~1

A

B

A = A^0

C

D E

D = C^1 = C~ = B~2

develop

E = C^2 = B^^2 = A~2^2

develop branch_2

F G

F = C^^ = A~4

G = E~ = C^2^ = A~2^2~

C = B^ = A^^ = A~~ C = A^1^1 = A~2C ≠ A^2

Page 17: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

OPINION TIME

Source: Giphy

Page 18: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

IF THE BEST WAY TO THINK ABOUT GIT ISCOMMIT TOPOLOGIES…

Page 19: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

ONE CONCEPT, ONE COMMIT

Page 20: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

“I don't know how many people look at Al's progression of patches, but they are stand-alone patches on their own, while at the same time _also_ being part of a larger migration to the inscrutable goals of Al - ie namespaces etc.

You may not realize just _how_ impressive that is, and what a absolute wonder it is to work with the guy.

Poetry in patches, indeed.”- Linus TorvaldsOn fa.linux.kernel, 27 Dec 2001

Source: Wikipedia

Page 21: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

CLEAN CODE ↔ CLEAN HISTORY

Page 22: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

PICK “TOO MANY COMMITS” OVER “TOO FEW”

Page 23: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

“History is the version of past events that people have decided to agree upon.”

- Attr. Napoleon Bonaparte

Source: Wikipedia

Page 24: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

REBASING

When you learn to rebase like a boss

Source: Giphy

Page 25: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

PUBLIC VERSUS PRIVATE BRANCHES

Page 26: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

When you force push to a public branch

Source: Giphy

Page 27: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

GARBAGE COLLECTION

Finding out git has a garbage collector when it deletes your accidentally untracked branch

Source: Giphy

Page 28: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

HISTORY METHODOLOGIES

Page 29: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Pure Merge (i.e. gitflow)

Pure Rebase (Keep Branch or Delete Branch)

Rebase Then Merge

Rebase With Squash (Mild/Major)

… A

D

E

F

Example Case: Feature

Develop… B

Page 30: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

F

Pure Merge

A

C D

E

G

Develop

Feature

B

Page 31: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Pure Rebase(Keep or Delete Branch)

A

B C

D

Develop

Feature

Page 32: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Rebase Then Merge

A

C D

E

Develop

Feature

B

F

Page 33: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

A

B D

E

Develop

FeatureF

Rebase With Squash

Page 34: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

THANKS

When I accidentally click ‘Merge pull request’

instead of ‘Comment’ in GitHub

Source: Giphy

Page 35: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

Arthur Doler

@arthurdoler

[email protected]

Page 36: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

RESOURCES

Page 37: Git 201 - A Deeper Look at Git - MDC 2017 · PDF fileGIT 201 - A DEEPER LOOK AT GIT Git Me With Your Best Shot Arthur Doler @arthurdoler arthurdoler@gmail.com

• Git from the Bottom Up (free!)• http://ftp.newartisans.com/pub/git.from.bottom.up.pdf

• Gitflow• http://nvie.com/posts/a-successful-git-branching-model/

• A Git Workflow for Agile Teams• http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html

• Git Team Workflows: merge or rebase?• http://blogs.atlassian.com/2013/10/git-team-workflows-merge-or-rebase/

• Git Pro Book (also free!)• http://git-scm.com/book

• Git pack files• http://git-scm.com/book/en/Git-Internals-Packfiles• http://stackoverflow.com/questions/5176225/are-gits-pack-files-deltas-rathe...