Getting Git Right

Preview:

Citation preview

A couple of Atlassians who get Git and dig the DAG

Tim PettersenDeveloper Advocate

@kannonboy

Ian BuchananDeveloper Advocate

@devpartisan

Git at Atlassian 10 minHappier Developers 40 min

A bit about Stash 10 mins

Better Teams 40 min

Break 10 min

Who knows

?

Facts

500 Developers

1000+ Nerds

Facts

working on 9 products

Facts

Tools

happy developers & productive teams Ship software

faster & smarter

Ship software faster & smarter

happy developers & productive teams

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

is just a tool!

Happier Developerwith

Be a

Explore & Understand

1

3

Fast & Compact

Control & Assemble4

Why does make you happy?

2 Freedom & Safety

5 minutes dive into

internals

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”

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

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

git add some-file.txt

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

zlib compressed SHA1

git commit -m "First commit"

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

Blob

Tree

Commit

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..

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

git add some-file.txt

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

Entirely new BLOB

git gc

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

PackfileLoose Objects

• Delta encoded • zlib compressed

Fast & Compact1

Everything is localExcept push & pull

Mostly C, written by Linux kernel and

filesystem developers

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

2 Freedom & Safety

Branching

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

work on a stack

So if your boss comes screaming at your desk

git stash Create a patch without a hassle

stash and branch FTW

Losing work is very hard

very very

Redundancy Every developer has a clone

Chain of “unlosability”

Recover a file

git checkout file-name

Recover a commit

git checkout sha-1

git checkout ref (branch/tag)or

Print file as of branch

git show branch:path/to/file

can be any ref

When all is lost, use the

reflog

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

garbage collected every

90 days

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

Explore & Understand 3

= history superpowers

Hard Questions of git logAsk

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

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

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

Who deleted that method?

git log -S<string> search through all history

Where is that pattern?

git grep <regexp> compare the speed between this

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

Have I merged this?

git branch --no-merged lists branches not merged

git branch --merged lists branches already merged

Control & Assemble4

Time machine without paradoxes?

What is a merge?

M

Merge commit

master

feature

merges keep the context of the feature’s commits

feature

master

tree f362c42032aff677c1a09c3f070454df5b411239

parent 49a906f5722ad446a131778cea52e3fda331b706

parent bd1174cd0f30fe9be9efdd41dcd56256340f230e

author Marcus Bertrand <mbertrand@atlassian.com> 1409002123 -0700

committer Marcus Bertrand <mbertrand@atlassian.com> 1409002123 -0700

!Merge branch 'foo/mybranch'

.git/objects/36/80d8c8fd182f97cb0e75045e2fed5c7b7613ed

commit

Anatomy of a merge

git knows the ancestry

1

2

The merge is local

powerful merge strategies3

merge is better in git

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

to merge changes!

recursiveresolve octopus subtreeours yours?

master

feature

What is a fast-forward merge?

master

It will just shift the HEAD tag

feature

merge strategy: resolve

Mmaster

feature

Three-way merge of the ancestors

Common ancestorMerge commit

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

merge becomes a non-event

rebase: Rewrite history with safety belts on

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

one by one, on top of a branch

master

feature

When you use merge…You pollute your feature branch with

non-meaningful merge commits

not really part of feature…

feature

master

meaningful merge

feature

master

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

What is an --interactive rebase?

Helps you clean up your private branches before publishing them

reword fixup

pick squash

edit exec

CUSTOMARY WARNING!

rebase rewrites history!

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

So what do I use? merge or rebase?

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

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

Explore & Understand

1

3

Fast & Compact

Control & Assemble4

Why does make you happy?

2 Freedom & Safety

Pro tips for the road

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

Happy DeveloperwithA

Productive TeamwithA

Improving Code Quality

1

2

Efficient Workflows

Git & Your Toolchain3

Why makes a team great!

Efficient Workflows

Git workflow?What’s the best

We don’t know!

+ different teams+ different products

different cultures

= different workflows

Git workflow?What’s the best

DesignWorkflows

your own

Issues Code

Issues Code

JIRA-456

JIRA-123JIRA-123

JIRA-456

Can’t be released right now

Unfinished features in your trunk / master branch

Branch per issueFirst:

feature/JIRA-30

stable master branch

isolated feature work

master

feature/JIRA-30-user-avatars

branch type

issue key

description

Branch per issueFirst:

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

branch type

issue key

description

Branch per issueFirst:

hotfix/JIRA-32-broke-ie8-again

branch type

issue key

description

Branch per issueFirst:

Typos happne!Tool switching sucks

Is the branch green?

Branch name pre-populated

master

Confounding build breakages

bugfix/JRA-1

master

Confounding build breakages

Is the branch green?

Branch name pre-populated

Atlassian Marketplace1Workflow

SAAS Workflow

Simplest Workflow

release from here

feature/JIRA-30

feature/JIRA-45

master

release from here

feature/JIRA-30

feature/JIRA-45

develop

master

integrate here

Simplest Workflow

Atlassian Stash2Workflow

Installable software

Multiple Product Versions

feature/JIRA-30

master

v 1.2

v 1.1

master

v 1.2

v 1.1

bugfix/JIRA-41

Multiple Product Versions

master

v 1.2

v 1.1

bugfix/JIRA-41

Multiple Product Versions

master

v 1.2

v 1.1

bugfix/JIRA-45

Multiple Product Versions

master

v 1.2

v 1.1

bugfix/JIRA-45

Multiple Product Versions

Multiple Product Versions

master

v 1.2

v 1.1

bugfix/JIRA-45

boring work

Automatic mergeswith Stash

Design your workflow

Nearly everything is possible with

Improving Code Quality

CodeReview

Photo: Yogi (Flickr)

Better Code

Shared Knowledge

Team Ownership

G = 1

R+1

Developer guilt

Team Ownership

Code Reviews

Pull Requests

Pull Requests

do it before merge

Pull Requests

Pull Request Creation

Pull Request Creation

Pull Request Creation

Discuss

Pull Request Creation

Discuss your changes

Side by side diff the choice is yours

Pull Request Merge Checks

Who would be

the best to reviewmy code?

Auto Suggest Reviewers

Free Add On For

committed code to this Pull Request

Suggestions:

contributed files that were modified

Git and your Toolchain

& CI

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

“I’m running the tests”

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

automatically triggered

Building branches

master

always build master

Every line of code starts with an

Issue

Visualize your development

Issue

Sprint Branch Pull Request

Build

2014 style

Visualize your development

Automatic Issue Transitions

master

IN REVIEW DONEIN PROGRESSOPEN

feature/JIRA-30

master

IN REVIEW DONEIN PROGRESSOPEN

Branch created!

Automatic Issue Transitions

feature/JIRA-30

master

IN REVIEW DONEIN PROGRESSOPEN

Pull Request Created!

Automatic Issue Transitions

feature/JIRA-30

master

IN REVIEW DONEIN PROGRESSOPEN

Pull Request Merged!

Automatic Issue Transitions

tinyurl.com/jirastashWebinar

See what’s going on

Builds

with

Bots

See what’s going onwith

Pages

Issues Branches Pull Requests etc.

See what’s going onwith

Issues Branches

Pull Requests etc.

See what’s going onwith

Why Git?

Ship software faster & smarter

So now you can answer

Why Git?„ „

Why ?

CommitLog

Git workflows for teams

Extensions &

Integrations

Scalability

Why ?

Git workflow for teams

feature/STASH-123

master

Forking

Branching

vs

feature/STASH-123

master

Git workflow for teams

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

feature/STASH-123

master

Git workflow for teams

Pull request merge checks

Repository hooks

Branch permissions

feature/STASH-123

master

Git workflow for teams

Pull request merge checks

Repository hooks

Branch permissions

Flexible & Extensible

Powerful integrations

Powerful integrations

• 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

insert /rest/api/latestRESTful APIs

RESTful APIs insert /rest/api/latest

Scalability

Request throttling

Request queuing

Scalability

Response Caching

Scalability

Clustering

Scalability

Git workflows for teams

Extensions &

Integrations

Scalability

Why ?

All sorts of teams are on

&

Ch ee se!want a shirt?

#gettinggitright

win wireless headphones

Fill out the survey

(check your mail)

#gettinggitright

Q & A$10 for up to 10 devs

Free for 5 users Totally free

Free basic version

Recommended