173

Getting Git Right

Embed Size (px)

Citation preview

Page 1: Getting Git Right
Page 2: Getting Git Right

A couple of Atlassians who get Git and dig the DAG

Tim PettersenDeveloper Advocate

@kannonboy

Ian BuchananDeveloper Advocate

@devpartisan

Page 3: Getting Git Right

Git at Atlassian 10 minHappier Developers 40 min

A bit about Stash 10 mins

Better Teams 40 min

Break 10 min

Page 4: Getting Git Right

Who knows

?

Page 5: Getting Git Right

Facts

500 Developers

Page 6: Getting Git Right

1000+ Nerds

Facts

Page 7: Getting Git Right

working on 9 products

Facts

Page 8: Getting Git Right

Tools

happy developers & productive teams Ship software

faster & smarter

Page 9: Getting Git Right

Ship software faster & smarter

happy developers & productive teams

Page 10: Getting Git Right
Page 11: Getting Git Right

Migrating soon?http://atlassian.com/git/

Page 12: Getting Git Right

is just a tool!

Page 13: Getting Git Right

Happier Developerwith

Be a

Page 14: Getting Git Right
Page 15: Getting Git Right

Explore & Understand

1

3

Fast & Compact

Control & Assemble4

Why does make you happy?

2 Freedom & Safety

Page 16: Getting Git Right

5 minutes dive into

internals

Page 17: Getting Git Right

Git is fundamentally a content-addressable filesystem with a VCS user interface written on top of it P ro G i t B o o k , S e c t i o n : G i t I n t e r n a l s”

Page 18: Getting Git Right

$> cd ~/repo-directory !$> ls -A !$> git init Initialized empty Git repository in ~/repo-directory/.git/ !$> ls -A .git

Page 19: Getting Git Right

$> tree .git/objects .git/objects !"" info #"" pack !2 directories

Page 20: Getting Git Right

git add some-file.txt

Page 21: Getting Git Right

$> tree .git/objects .git/objects !"" e4 $   #"" 3a6ac59164adadac854d591001bbb10086f37d !"" info #"" pack !3 directories, 1 file

zlib compressed SHA1

Page 22: Getting Git Right

git commit -m "First commit"

Page 23: Getting Git Right

$> tree .git/objects .git/objects !"" 13 $   #"" 1e360ae1a0c08acd18182c6160af6a83e0d22f !"" 31 $   #"" 995f2d03aa31ee97ee2e814c9f0b0ffd814316 !"" e4 $   #"" 3a6ac59164adadac854d591001bbb10086f37d !"" info #"" pack !5 directories, 3 files

Blob

Tree

Commit

Page 24: Getting Git Right

cba0a..

committree

contentblob

contentblob

contentblob

98ca9..92ec2..

5b1d3..

911e7..

cba0a..

tree 92ec2..

blob 5b1d3..blob 911e7..blob

authorcommitter

READMELICENSEtest.rb

sizesize

size

size

size

data model

parent e34bf..

Page 25: Getting Git Right

echo "// Comment" >> some-file.txt

Page 26: Getting Git Right

git add some-file.txt

Page 27: Getting Git Right

$> tree .git/objects .git/objects !"" 13 $   #"" 1e360ae1a0c08acd18182c6160af6a83e0d22f !"" 31 $   #"" 995f2d03aa31ee97ee2e814c9f0b0ffd814316 !"" c1 $   #"" 9e6823e34980033917b6427f3e245ce2102e6e !"" e4 $   #"" 3a6ac59164adadac854d591001bbb10086f37d !6 directories, 4 files

Entirely new BLOB

Page 28: Getting Git Right

git gc

Page 29: Getting Git Right

$> tree .git/objects .git/objects !"" info $   #"" packs #"" pack !"" pack-7475314b451a882d77b1535d215def8bad0f4306.idx #"" pack-7475314b451a882d77b1535d215def8bad0f4306.pack !2 directories, 3 files

Page 30: Getting Git Right

PackfileLoose Objects

• Delta encoded • zlib compressed

Page 31: Getting Git Right

Fast & Compact1

Page 32: Getting Git Right

Everything is localExcept push & pull

Page 33: Getting Git Right

Mostly C, written by Linux kernel and

filesystem developers

Page 34: Getting Git Right

But what if my repo is big?

446k lines of code added

1

3

Linux Kernel release has 15+ million LOC

1,339 contributors4

2 12,000 non-merge commits

source lwn.net

Page 35: Getting Git Right

2 Freedom & Safety

Page 36: Getting Git Right

Branching

Page 37: Getting Git Right

git stash is awesomeIt’s a way to temporarily save your

work on a stack

Page 38: Getting Git Right

So if your boss comes screaming at your desk

Page 39: Getting Git Right

git stash Create a patch without a hassle

Page 40: Getting Git Right

stash and branch FTW

Page 41: Getting Git Right

Losing work is very hard

very very

Page 42: Getting Git Right

Redundancy Every developer has a clone

Page 43: Getting Git Right

Chain of “unlosability”

Page 44: Getting Git Right

Recover a file

git checkout file-name

Page 45: Getting Git Right

Recover a commit

git checkout sha-1

git checkout ref (branch/tag)or

Page 46: Getting Git Right

Print file as of branch

git show branch:path/to/file

can be any ref

Page 47: Getting Git Right

When all is lost, use the

reflog

Page 48: Getting Git Right

What is the reflog?it’s a log of all the places where your HEAD has been

garbage collected every

90 days

Page 49: Getting Git Right

More on recovery!http://bit.do/recovering

Page 50: Getting Git Right

Explore & Understand 3

Page 51: Getting Git Right

= history superpowers

Hard Questions of git logAsk

-S string in all diffs--after,--before when?--author who did what

Page 52: Getting Git Right

Who deleted that file?git log -1 -- [path] lists where a file was deleted

git log --diff-filter=D --summary lists all deleted files

Page 53: Getting Git Right

Who deleted that method?

git log -S<string> search through all history

Page 54: Getting Git Right

Where is that pattern?

git grep <regexp> compare the speed between this

and regular grep or ack…!you’ll be blown away

Page 55: Getting Git Right

Have I merged this?

git branch --no-merged lists branches not merged

git branch --merged lists branches already merged

Page 56: Getting Git Right

Control & Assemble4

Page 57: Getting Git Right

Time machine without paradoxes?

Page 58: Getting Git Right

What is a merge?

M

Merge commit

master

feature

merges keep the context of the feature’s commits

feature

master

Page 59: Getting Git Right

tree f362c42032aff677c1a09c3f070454df5b411239

parent 49a906f5722ad446a131778cea52e3fda331b706

parent bd1174cd0f30fe9be9efdd41dcd56256340f230e

author Marcus Bertrand <[email protected]> 1409002123 -0700

committer Marcus Bertrand <[email protected]> 1409002123 -0700

!Merge branch 'foo/mybranch'

.git/objects/36/80d8c8fd182f97cb0e75045e2fed5c7b7613ed

commit

Anatomy of a merge

Page 60: Getting Git Right

git knows the ancestry

1

2

The merge is local

powerful merge strategies3

merge is better in git

Page 61: Getting Git Right

Let’s talk about merge strategies!git has breadth of choice

to merge changes!

recursiveresolve octopus subtreeours yours?

Page 62: Getting Git Right

master

feature

What is a fast-forward merge?

master

It will just shift the HEAD tag

feature

Page 63: Getting Git Right

merge strategy: resolve

Mmaster

feature

Three-way merge of the ancestors

Common ancestorMerge commit

Page 64: Getting Git Right

3-way merge but climbs the ancestry tree recursively if there are multiple ancestors

merge strategy: recursive

M

M

feature

masterancesto

r 1

ancestor 2

ancestor 3

Page 65: Getting Git Right

merge becomes a non-event

Page 66: Getting Git Right

rebase: Rewrite history with safety belts on

Page 67: Getting Git Right

What is a rebase?It’s a way to replay commits,

one by one, on top of a branch

master

feature

Page 68: Getting Git Right

When you use merge…You pollute your feature branch with

non-meaningful merge commits

not really part of feature…

feature

master

meaningful merge

Page 69: Getting Git Right

feature

master

What is a rebase?It can be used to keep a feature branch up to date with master

Page 70: Getting Git Right

What is an --interactive rebase?

Helps you clean up your private branches before publishing them

reword fixup

pick squash

edit exec

Page 71: Getting Git Right

CUSTOMARY WARNING!

rebase rewrites history!

Treat this power with great care. Only rewrite history of local branches or…

Page 72: Getting Git Right

So what do I use? merge or rebase?

Page 73: Getting Git Right

Merge Commit Rebase (FF) Rebase (Squash)

No merge commits

Verbose history

Easy to read

Can be more difficult to trace changes

Which should I use?

“Ugly” history

Full traceability

Hard to screw up

mostlysome

Page 74: Getting Git Right

Read more on the topic!bit.do/merge-or-rebase

Page 75: Getting Git Right

Explore & Understand

1

3

Fast & Compact

Control & Assemble4

Why does make you happy?

2 Freedom & Safety

Page 76: Getting Git Right

Pro tips for the road

Page 77: Getting Git Right

Get all the alias goodness on Bitbuckethttp://bit.do/git-aliases

Page 78: Getting Git Right
Page 79: Getting Git Right

Happy DeveloperwithA

Page 80: Getting Git Right
Page 81: Getting Git Right

Productive TeamwithA

Page 82: Getting Git Right

Improving Code Quality

1

2

Efficient Workflows

Git & Your Toolchain3

Why makes a team great!

Page 83: Getting Git Right

Efficient Workflows

Page 84: Getting Git Right

Git workflow?What’s the best

We don’t know!

Page 85: Getting Git Right

+ different teams+ different products

different cultures

= different workflows

Git workflow?What’s the best

Page 86: Getting Git Right

DesignWorkflows

your own

Page 87: Getting Git Right

Issues Code

Page 88: Getting Git Right

Issues Code

JIRA-456

JIRA-123JIRA-123

JIRA-456

Page 89: Getting Git Right

Can’t be released right now

Unfinished features in your trunk / master branch

Page 90: Getting Git Right

Branch per issueFirst:

feature/JIRA-30

stable master branch

isolated feature work

master

Page 91: Getting Git Right

feature/JIRA-30-user-avatars

branch type

issue key

description

Branch per issueFirst:

Page 92: Getting Git Right

bugfix/JIRA-31-oauth-3lo-NPE

branch type

issue key

description

Branch per issueFirst:

Page 93: Getting Git Right

hotfix/JIRA-32-broke-ie8-again

branch type

issue key

description

Branch per issueFirst:

Page 94: Getting Git Right

Typos happne!Tool switching sucks

Page 95: Getting Git Right
Page 96: Getting Git Right
Page 97: Getting Git Right

Is the branch green?

Branch name pre-populated

Page 98: Getting Git Right

master

Confounding build breakages

Page 99: Getting Git Right

bugfix/JRA-1

master

Confounding build breakages

Page 100: Getting Git Right

Is the branch green?

Branch name pre-populated

Page 101: Getting Git Right

Atlassian Marketplace1Workflow

SAAS Workflow

Page 102: Getting Git Right

Simplest Workflow

release from here

feature/JIRA-30

feature/JIRA-45

master

Page 103: Getting Git Right

release from here

feature/JIRA-30

feature/JIRA-45

develop

master

integrate here

Simplest Workflow

Page 104: Getting Git Right

Atlassian Stash2Workflow

Installable software

Page 105: Getting Git Right

Multiple Product Versions

feature/JIRA-30

master

v 1.2

v 1.1

Page 106: Getting Git Right

master

v 1.2

v 1.1

bugfix/JIRA-41

Multiple Product Versions

Page 107: Getting Git Right

master

v 1.2

v 1.1

bugfix/JIRA-41

Multiple Product Versions

Page 108: Getting Git Right

master

v 1.2

v 1.1

bugfix/JIRA-45

Multiple Product Versions

Page 109: Getting Git Right

master

v 1.2

v 1.1

bugfix/JIRA-45

Multiple Product Versions

Page 110: Getting Git Right

Multiple Product Versions

master

v 1.2

v 1.1

bugfix/JIRA-45

boring work

Page 111: Getting Git Right

Automatic mergeswith Stash

Page 112: Getting Git Right

Design your workflow

Nearly everything is possible with

Page 113: Getting Git Right

Improving Code Quality

Page 114: Getting Git Right

CodeReview

Photo: Yogi (Flickr)

Page 115: Getting Git Right

Better Code

Shared Knowledge

Team Ownership

Page 116: Getting Git Right

G = 1

R+1

Developer guilt

Page 117: Getting Git Right

Team Ownership

Page 118: Getting Git Right

Code Reviews

Page 119: Getting Git Right

Pull Requests

Page 120: Getting Git Right

Pull Requests

Page 121: Getting Git Right

do it before merge

Pull Requests

Page 122: Getting Git Right

Pull Request Creation

Page 123: Getting Git Right

Pull Request Creation

Page 124: Getting Git Right

Pull Request Creation

Page 125: Getting Git Right

Discuss

Pull Request Creation

Page 126: Getting Git Right

Discuss your changes

Page 127: Getting Git Right

Side by side diff the choice is yours

Page 128: Getting Git Right

Pull Request Merge Checks

Page 129: Getting Git Right

Who would be

the best to reviewmy code?

Page 130: Getting Git Right

Auto Suggest Reviewers

Free Add On For

Page 131: Getting Git Right

committed code to this Pull Request

Suggestions:

contributed files that were modified

Page 132: Getting Git Right

Git and your Toolchain

Page 133: Getting Git Right

& CI

Page 134: Getting Git Right

Comic: Randall Munroe http://xkcd.com/303/

Page 135: Getting Git Right

“I’m running the tests”

Comic: Randall Munroe http://xkcd.com/303/

Page 136: Getting Git Right

automatically triggered

Building branches

master

always build master

Page 137: Getting Git Right

Every line of code starts with an

Issue

Page 138: Getting Git Right

Visualize your development

Issue

Sprint Branch Pull Request

Build

2014 style

Page 139: Getting Git Right

Visualize your development

Page 140: Getting Git Right

Automatic Issue Transitions

master

IN REVIEW DONEIN PROGRESSOPEN

Page 141: Getting Git Right

feature/JIRA-30

master

IN REVIEW DONEIN PROGRESSOPEN

Branch created!

Automatic Issue Transitions

Page 142: Getting Git Right

feature/JIRA-30

master

IN REVIEW DONEIN PROGRESSOPEN

Pull Request Created!

Automatic Issue Transitions

Page 143: Getting Git Right

feature/JIRA-30

master

IN REVIEW DONEIN PROGRESSOPEN

Pull Request Merged!

Automatic Issue Transitions

Page 144: Getting Git Right
Page 145: Getting Git Right

tinyurl.com/jirastashWebinar

Page 146: Getting Git Right

See what’s going on

Builds

with

Page 147: Getting Git Right

Bots

See what’s going onwith

Page 148: Getting Git Right

Pages

Issues Branches Pull Requests etc.

See what’s going onwith

Page 149: Getting Git Right

Issues Branches

Pull Requests etc.

See what’s going onwith

Page 150: Getting Git Right

Why Git?

Ship software faster & smarter

Page 151: Getting Git Right

So now you can answer

Why Git?„ „

Page 152: Getting Git Right

Why ?

Page 153: Getting Git Right

CommitLog

Page 154: Getting Git Right

Git workflows for teams

Extensions &

Integrations

Scalability

Why ?

Page 155: Getting Git Right

Git workflow for teams

feature/STASH-123

master

Forking

Branching

vs

Page 156: Getting Git Right

feature/STASH-123

master

Git workflow for teams

X reviewers approved? Y builds passed? All tasks complete?

Page 157: Getting Git Right

feature/STASH-123

master

Git workflow for teams

Pull request merge checks

Repository hooks

Branch permissions

Page 158: Getting Git Right

feature/STASH-123

master

Git workflow for teams

Pull request merge checks

Repository hooks

Branch permissions

Flexible & Extensible

Page 159: Getting Git Right

Powerful integrations

Page 160: Getting Git Right

Powerful integrations

Page 161: Getting Git Right

• Full Java API • Repository Hooks • Merge Checks • User Interface • REST end-points • Filetype renderers • SSH commands

Stash Platform

Branch Permissions REST APIs JIRA

Integration

Source? You betcha!

Plugin APIs

Page 162: Getting Git Right

insert /rest/api/latestRESTful APIs

Page 163: Getting Git Right

RESTful APIs insert /rest/api/latest

Page 164: Getting Git Right

Scalability

Request throttling

Page 165: Getting Git Right

Request queuing

Scalability

Page 166: Getting Git Right

Response Caching

Scalability

Page 167: Getting Git Right

Clustering

Scalability

Page 168: Getting Git Right

Git workflows for teams

Extensions &

Integrations

Scalability

Why ?

Page 169: Getting Git Right

All sorts of teams are on

&

Page 170: Getting Git Right
Page 171: Getting Git Right

Ch ee se!want a shirt?

#gettinggitright

Page 172: Getting Git Right

win wireless headphones

Fill out the survey

(check your mail)

#gettinggitright

Page 173: Getting Git Right

Q & A$10 for up to 10 devs

Free for 5 users Totally free

Free basic version