You are on page 1of 173

Tim Pettersen

Developer Advocate

@kannonboy

Ian Buchanan
Developer Advocate

@devpartisan

A couple of Atlassians who get Git and dig the DAG

Git at Atlassian
10 min
Happier Developers
40 min
Break
10 min
Better Teams
40 min
A bit about Stash
10 mins

Who knows

Facts

500 Developers

Facts

1000+ Nerds

Facts

working on 9 products

happy developers &


productive teams

Tools

Ship software
faster & smarter

happy developers &


productive teams

Ship software
faster & smarter

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

is just a tool!

Be a

Happier Developer
with

Why does

make you happy?

Fast & Compact

Freedom & Safety

Explore & Understand

Control & Assemble

5 minutes dive into

internals

Git is fundamentally a content-addressable


filesystem with a VCS user interface written
on top of it

Pro Git Book, Section: Git Internals

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

Commit
Tree
Blob

data model
98ca9..

commit

size

e34bf..
parent
author
committer
tree
92ec2..

5b1d3..

blob

content

92ec2..

tree
blob 5b1d3..
blob 911e7..
blob cba0a..

size

911e7..
size

README
LICENSE

test.rb

blob

size

content
cba0a..

blob

content

size

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

git add some-file.txt

$> tree .git/objects


.git/objects
!"" 13
$ #"" 1e360ae1a0c08acd18182c6160af6a83e0d22f
!"" 31
$ #"" 995f2d03aa31ee97ee2e814c9f0b0ffd814316
!"" c1
$ #"" 9e6823e34980033917b6427f3e245ce2102e6e
Entirely new BLOB
!"" e4
$ #"" 3a6ac59164adadac854d591001bbb10086f37d
!

6 directories, 4 files

git gc

$> tree .git/objects


.git/objects
!"" info
$ #"" packs
#"" pack
!"" pack-7475314b451a882d77b1535d215def8bad0f4306.idx
#"" pack-7475314b451a882d77b1535d215def8bad0f4306.pack
!

2 directories, 3 files

Loose Objects

Packfile

Delta encoded
zlib compressed

Fast & Compact

Everything is local

Except push & pull

Mostly C,
written by Linux kernel and
filesystem developers

But what if my repo is big?


1

Linux Kernel release has 15+ million LOC

12,000 non-merge commits

446k lines of code added

1,339 contributors
source lwn.net

Freedom & Safety

Branching

git stash is awesome


Its 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

or
git checkout ref (branch/tag)

Print file as of branch


can be any ref

git show branch:path/to/file

When all is lost, use the

reflog

What is the reflog?


its 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

Ask

Hard Questions of git log


--author who did what
--after,--before when?
-S string
in all dis
= history superpowers

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!
youll be blown away

Have I merged this?


git branch --no-merged
lists branches not merged

git branch --merged


lists branches already merged

Control & Assemble

Time machine without paradoxes?

What is a merge?
merges keep the context of
the features commits
Merge commit

re

u
at
e
f

feature

master

er
t
s

Anatomy of a merge
.git/objects/36/80d8c8fd182f97cb0e75045e2fed5c7b7613ed

commit

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'

merge is better in git


1

The merge is local

git knows the ancestry

powerful merge strategies

Lets talk about merge strategies!


git has breadth of choice
to merge changes!

resolve

recursive

octopus

ours

subtree

yours?

What is a fast-forward merge?


It will just shift the HEAD tag

re

u
at
e
f

feature

master
m

r
te
s
a

merge strategy: resolve


Three-way merge of the ancestors
Merge commit

Common ancestor

feature

master

merge strategy: recursive


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

ce
n
a

master

ancestor 3

feature

ce
n
a

r2
o
st

merge becomes a
non-event

rebase: Rewrite history


with safety belts on

What is a rebase?
Its a way to replay commits,
one by one, on top of a branch

feature

master

When you use merge


You pollute your feature branch with
non-meaningful merge commits
meaningful
merge
master

feature

not really part


of feature

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

feature

What is an
--interactive rebase?
Helps you clean up your private
branches before publishing them

pick
squash

reword
fixup

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?

Which should I use?


Merge Commit

Rebase (FF)

Rebase (Squash)

Ugly history

No merge commits

Easy to read

Full traceability

Verbose history

Hard to screw up

mostly

some

Can be more difficult


to trace changes

Read more on the topic!


bit.do/merge-or-rebase

Why does

make you happy?

Fast & Compact

Freedom & Safety

Explore & Understand

Control & Assemble

Pro tips for the road

Get all the alias goodness on Bitbucket


http://bit.do/git-aliases

Happy Developerwith

Productive Team with

Why

makes a team great!

Eicient Workflows

Improving Code Quality

Git & Your Toolchain

Ecient Workflows

We dont know!

Whats the best


Git workflow?

Whats the best


Git workflow?

different cultures
+ different products
+ different teams
= different workflows

Design

your own

Workflows

Issues

Code

Issues

Code
JIRA-123

JIRA-456

JIRA-123

JIRA-456

Cant be released right now

Unfinished features in your trunk / master branch

First:

Branch per issue


stable master branch

master

feature/JIRA-30

isolated feature work

First:

Branch per issue


branch type

description

feature/JIRA-30-user-avatars
issue key

First:

Branch per issue


branch type

description

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

First:

Branch per issue


branch type

description

hotfix/JIRA-32-broke-ie8-again
issue key

Typos happne!
Tool switching sucks

Is the branch green?

Branch name
pre-populated

Confounding build breakages

master

Confounding build breakages

bugfix/JRA-1

master

Is the branch green?

Branch name
pre-populated

SAAS Workflow

1 Atlassian MarketplaceWorkflow

Simplest Workflow
release from here

master

feature/JIRA-30

feature/JIRA-45

Simplest Workflow
release from here
master

develop

feature/JIRA-30

feature/JIRA-45

integrate here

Installable software

2 Atlassian Stash

Workflow

Multiple Product Versions


v 1.1

v 1.2

master

feature/JIRA-30

Multiple Product Versions

v 1.1

bugfix/JIRA-41

v 1.2

master

Multiple Product Versions

v 1.1

bugfix/JIRA-41

v 1.2

master

Multiple Product Versions


bugfix/JIRA-45

v 1.1

v 1.2

master

Multiple Product Versions


bugfix/JIRA-45

v 1.1

v 1.2

master

Multiple Product Versions


bugfix/JIRA-45

v 1.1

v 1.2

master

boring work

Automatic merges

with Stash

Nearly everything is possible with

Design your workflow

Improving
Code Quality

Photo: Yogi (Flickr)

Code
Review

Better
Code

Shared
Knowledge

Team
Ownership

Developer guilt

=
G

1
R+1

Team
Ownership

Code Reviews


Pull Requests

Pull Requests

Pull Requests

do it before merge

Pull Request Creation

Pull Request Creation

Pull Request Creation

Pull Request Creation

Discuss

Discuss your changes

Side by side diff

the choice is yours

Pull Request Merge Checks

Who would be

the best to review

my code?

Auto Suggest Reviewers


Free

Add
O

n Fo

Suggestions:
committed code to this
Pull Request

contributed files that


were modified

Git and your


Toolchain

& CI

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

Im running the tests

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

Building branches
always build master

master

automatically
triggered

Every line of code starts with an

Issue

Visualize your development


2014 style

Issue

Sprint

Build

Branch

Pull Request

Visualize your development

Automatic Issue Transitions


master

OPEN

IN PROGRESS

IN REVIEW

DONE

Automatic Issue Transitions


master

Branch created!
feature/JIRA-30

OPEN

IN PROGRESS

IN REVIEW

DONE

Automatic Issue Transitions


master

feature/JIRA-30

Pull Request Created!

OPEN

IN PROGRESS

IN REVIEW

DONE

Automatic Issue Transitions


master

Pull Request Merged!


feature/JIRA-30

OPEN

IN PROGRESS

IN REVIEW

DONE

Webinar

tinyurl.com/jirastash

See whats going on


with
Builds

See whats going on


with
Bots

See whats going on


with
Pages

Issues
Branches
Pull Requests
etc.

See whats going on


with

Issues
Branches
Pull Requests
etc.

Why Git?
Ship software faster & smarter

So now you can answer

Why Git?

Why

Commit
Log

Why

Git workflows
for teams

Extensions
&
Integrations

Scalability

Git workflow for teams


Forking
vs
Branching

master

feature/STASH-123

Git workflow for teams


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

feature/STASH-123

Git workflow for teams


master

feature/STASH-123

Pull request merge checks


Repository hooks
Branch permissions

Git workflow for teams


master

feature/STASH-123

Pull request merge checks


Repository hooks
Branch permissions

Flexible &
Extensible

Powerful integrations

Powerful integrations

Plugin APIs
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!

RESTful APIs

insert /rest/api/latest

RESTful APIs

insert /rest/api/latest

Scalability

Request throttling

Scalability

Request queuing

Scalability

Response Caching

Scalability

Clustering

Why

Git workflows
for teams

Extensions
&
Integrations

Scalability

All sorts of teams


are on
&

Ch ee se!
want a shirt?

#gettinggitright

Fill out the survey


win wireless headphones
(check your mail)

#gettinggitright

Q&A
$10 for up to 10 devs

Free for 5 users

Free basic version

Totally free

You might also like