Using Git to Manage and Deploy Rails Apps

Preview:

DESCRIPTION

Git is a stupid content tracker used primarily as a distributed source code management system that is beginning to get a lot of use in the Rails community, including a new Capistrano SCM module, a new Peepcast episode focused on it, and the Rubinius project switching to it.This talk will first demonstrate how Git works at a technical level, including descriptions of the object database, the index file, the working directory, the main Git object types and the plumbing toolkit. We will first show how Git is primarily a tree history storage and directory content management system, and then demonstrate how an SCM is built on top of that.It will then cover how you can use Git to manage a software project with a distributed team. This will cover creating a new Git repository, exporting public or external repositories, branching and merging, pushing and pulling between users repositories, and tagging. We will also go over how to use Git to work with SVN projects and how to convert an SVN project to Git.Lastly, we will go over how to deploy a Rails app with Capistrano’s new Git SCM module. Since Capistrano 2.1, Git is a supported SCM, and this talk will cover how to set it up and what options are available.

Citation preview

Getting GitScott Chacon

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

2m This Slide10%

4 min

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min2m Who is Scott?

10%

4 min

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

75%

35 min

3m What is Git?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

75%

35 min

20m How Does Git Work?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

75%

35 min

12m How Do I Use Git?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

4m How Do I Deploy with Git?15%

6 min

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

2m Where Can I Learn More?

15%

6 min

Who Is Scott?Introducing myself...

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min2m Who is Scott?

10%

4 min

Scott Anthony Chacon

github.com/schacon

www.gitcasts.com

RailsGitXen3D CamerasHuge Flat Screensjepoirrier@flickr

me

introduce yourself

introduce yourselfand your sweet projects...

why is scott here?

What is Git?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

75%

35 min

3m What is Git?

git is

directory contentmanagement system

git is

tree history storage system

git is

stupid content tracker

git is

a toolkit

git is

the “plumbing”

the “porcelain”

not subversion!

git is

forget subversion!

not an evolution

svnrcs cvs git

not an evolution

svnrcs cvs git

not an evolution

svnrcs cvs git

not an evolution

source control taxonomy

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

source control taxonomy

deltastorage

file A !1

file B

file C

C1 C2 C3 C4 C5

!2

!1 !2

!1 !2 !3

A

B

C

C1 C2 C3 C4 C5

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

DAGstorage

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

svncvs

git

perforce

mercurial

time machinecp -r

rcs

source control taxonomy

darcs

deltastorage

DAGstorage

bazzar

bitkeeper

local

centralized

distributed

local

centralized

distributed

source control taxonomy

bazaar

How Does Git Work?

How Does Git Work?

?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

75%

35 min

20m How Does Git Work?

git

git directory

git directory

.git

git directory

.git

GIT_DIR

Git Directoryconfig file

hooks

index

object database

references

object database

object databasecontent

object database

new_content = type + ’ ‘ + content.size + \0 + content

content

object database

new_content = type + ’ ‘ + content.size + \0 + content

content “header”

object database

new_content = type + ’ ‘ + content.size + \0 + content

sha = Digest::SHA1.hexdigest(new_content)

content

object database

new_content = type + ’ ‘ + content.size + \0 + content

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

object database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

object database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

path = “.git/objects/82/4aed035c0aa75d64c...”

object database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

path = “.git/objects/82/4aed035c0aa75d64c...”

File.open(path, ‘w’) {|f| f.write(compressed)}

object database

new_content = type + ’ ‘ + content.size + \0 + content

compressed = zlib::deflate(new_content)

sha = Digest::SHA1.hexdigest(new_content)

content

“824aed035c0aa75d64c...”

path = “.git/objects/82/4aed035c0aa75d64c...”

File.open(path, ‘w’) {|f| f.write(compressed)}

“loose” format

object databasegit gc

object databasegit gc

same file with minor differences

object database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

same file with minor differences

object database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

.git/objects/pack/pack-999727..9f600.pack

.git/objects/pack/pack-999727..9f600.idx

same file with minor differences

object database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

.git/objects/pack/pack-999727..9f600.pack

.git/objects/pack/pack-999727..9f600.idx

same file with minor differences

object database

.git/objects/f1/032eed02413a1145c...

git gc

.git/objects/45/b983be36b73c0788d...

.git/objects/04/fb8aee105e6e445e8...

.git/objects/63/874f37013c1740acd...

.git/objects/1d/c9cbcb76cbb80fce1...

.git/objects/82/4aed035c0aa75d64c...

.git/objects/pack/pack-999727..9f600.pack

.git/objects/pack/pack-999727..9f600.idx

same file with minor differences

“packed” format

object database

all git objects are stored this way

object database

new_content = type + ’ ‘ + content.size + \0 + content

4 types of git objects

object database

blob

object database

blob tree

object database

commit

blob tree

object database

commit tag

blob tree

object database

blob

Rakele

README

simplegit.rb

./

lib/

blob : a874b7

blob : a906cb

blob : a0a60a

Working Directory Git Directory

object databaseblob

object database{SimpleGit Ruby Library======================

This library calls git commands and returns the output.

Author : Scott Chacon

blob [content size]\0

Zlib::Inflate

blob : a906cb

zlib::deflate

object database{SimpleGit Ruby Library======================

This library calls git commands and returns the output.

Author : Scott Chacon

blob [content size]\0

Zlib::Inflate

blob : a906cb

content

zlib::deflate

object database{SimpleGit Ruby Library======================

This library calls git commands and returns the output.

Author : Scott Chacon

blob [content size]\0

Zlib::Inflate

blob : a906cb

content

header

zlib::deflate

object database{SimpleGit Ruby Library======================

This library calls git commands and returns the output.

Author : Scott Chacon

blob [content size]\0

Zlib::Inflate

blob : a906cb

content

header

compress zlib::deflate

object database{SimpleGit Ruby Library======================

This library calls git commands and returns the output.

Author : Scott Chacon

blob [content size]\0

Zlib::Inflate

blob : a906cb

content

header

compress

object

zlib::deflate

object database

commit tag

blob tree

object database

tree

object databasetree

Rakele

README

simplegit.rb

./

lib/

blob : a874b7

blob : a906cb

blob : a0a60a

Working Directory Git Directory

object databasetree

Rakele

README

simplegit.rb

./

lib/

tree : 1a738d

tree : fe8971

Working Directory Git Directory

blob : a874b7

blob : a906cb

blob : a0a60a

object database{100644 blob a906cb README100644 blob a874b7 Rakefile040000 tree fe8971 lib

tree [content size]\0

tree : 1a738d

Zlib::Inflatezlib::deflate

object database{100644 blob a906cb README100644 blob a874b7 Rakefile040000 tree fe8971 lib

tree [content size]\0

tree : 1a738d

Zlib::Inflate

filename“inode” info

zlib::deflate

object database{100644 blob a906cb README100644 blob a874b7 Rakefile040000 tree fe8971 lib

tree [content size]\0

tree : 1a738d

Zlib::Inflate

“block pointer”typemode

zlib::deflate

object database

commit tag

blob tree

object database

commit

commit

tree

blob

tree

tree blob

blob

branch

HEAD

object databasecommit

object database{Zlib::Inflate

tree e1b3ecparent a11befauthor Scott Chacon <schacon@gmail.com> 1205624433committer Scott Chacon <schacon@gmail.com> 1205624433

my second commit, which is better than the first

commit [content size]\0

commit : e1b3ec

zlib::deflate

object database{Zlib::Inflate

tree e1b3ecparent a11befauthor Scott Chacon <schacon@gmail.com> 1205624433committer Scott Chacon <schacon@gmail.com> 1205624433

my second commit, which is better than the first

commit [content size]\0

commit : e1b3ec

zlib::deflate

object database{Zlib::Inflate

tree e1b3ecparent a11befauthor Scott Chacon <schacon@gmail.com> 1205624433committer Scott Chacon <schacon@gmail.com> 1205624433

my second commit, which is better than the first

commit [content size]\0

commit : e1b3ec

zlib::deflate

object database{Zlib::Inflate

tree e1b3ecparent a11befauthor Scott Chacon <schacon@gmail.com> 1205624433committer Scott Chacon <schacon@gmail.com> 1205624433

my second commit, which is better than the first

commit [content size]\0

commit : e1b3ec

zlib::deflate

object database{Zlib::Inflate

tree e1b3ecparent a11befauthor Scott Chacon <schacon@gmail.com> 1205624433committer Scott Chacon <schacon@gmail.com> 1205624433

my second commit, which is better than the first

commit [content size]\0

commit : e1b3ec

zlib::deflate

blob

branch

HEAD

commit

remote

tree

tag

object database

object database

commit tag

blob tree

object database

tag

blob

branch

HEAD

commit

remote

tree

tag

object databasetag

object database{Zlib::Inflate

object 0576fatype committag v0.1tagger Scott Chacon <schacon@gmail.com> 1205624655

this is my v0.1 tag

tag [content size]\0

tag : 0c819c

zlib::deflate

object database{Zlib::Inflate

object 0576fatype committag v0.1tagger Scott Chacon <schacon@gmail.com> 1205624655

this is my v0.1 tag

tag [content size]\0

tag : 0c819c

zlib::deflate

object database{Zlib::Inflate

object 0576fatype committag v0.1tagger Scott Chacon <schacon@gmail.com> 1205624655

this is my v0.1 tag

tag [content size]\0

tag : 0c819c

zlib::deflate

object database{Zlib::Inflate

object 0576fatype committag v0.1tagger Scott Chacon <schacon@gmail.com> 1205624655

this is my v0.1 tag

tag [content size]\0

tag : 0c819c

zlib::deflate

object database{Zlib::Inflate

object 0576fatype committag v0.1tagger Scott Chacon <schacon@gmail.com> 1205624655

this is my v0.1 tag

tag [content size]\0

tag : 0c819c

zlib::deflate

object database

commit tag

blob tree

object database

commit tag

blob tree

immutable

object database

commit tag

blob tree

immutable

can’t be muted

Git Directoryconfig file

hooks

index

object database

references

references

blob

branch

HEAD

commit

remote

tree

tag

referenceslightweight, movablepointers to a commit

blob

branch

HEAD

commit

remote

tree

tag

referenceslightweight, movablepointers to a commit

stored in .git/refs/*as simple files

blob

branch

HEAD

commit

remote

tree

tag

references

the object model

commit

tree

blob

tree

tree blob

blob

branch

HEAD

commit

tree

blob

tree

tree blob

blob

branch

HEAD

commit

tree

blob

tree

tree blob

blob

branch

HEAD

commit

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

blob

branch

HEAD

tag

commit

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

blob

branch

HEAD

tag

commit

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

blob

branch

HEAD

tag

commit

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

blob

branch

HEAD

tag

commit

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

blob

branch

HEAD

tag

commit

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

blob

branch

HEAD

tag

commit

tag

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

commit

tree

blob

blob

branch

HEAD

commit

tag

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

commit

tree

blob

blob

branch

HEAD

commit

tag

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

commit

tree

blob

blob

branch

HEAD

commit

tag

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

commit

tree

blob

blob

branch

HEAD

commit

tag

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

commit

tree

blob

blob

branch

HEAD

commit

tag

tree

blob

tree

tree

commit

tree

blob

tree

tree blob

commit

tree

blob

blob

branch

HEAD

commit : a11bef

tag : 0c819c

tree : 1a738d

tree : fe8971

blob : a874b7

blob : a906cb

blob : a0a60a

README

Rakefile

lib

simplegit.rb

$ git checkout v0.1

.git/refs/tags/v0.1 "0c819c"

1

2

3

commit : a11bef

tag : 0c819c

tree : 1a738d

tree : fe8971

blob : a874b7

blob : a906cb

blob : a0a60a

README

Rakefile

lib

simplegit.rb

$ git checkout v0.1

.git/refs/tags/v0.1 "0c819c"

1

2

3

commit : a11bef

tag : 0c819c

tree : 1a738d

tree : fe8971

blob : a874b7

blob : a906cb

blob : a0a60a

README

Rakefile

lib

simplegit.rb

$ git checkout v0.1

.git/refs/tags/v0.1 "0c819c"

1

2

3

commit : a11bef

tag : 0c819c

tree : 1a738d

tree : fe8971

blob : a874b7

blob : a906cb

blob : a0a60a

README

Rakefile

lib

simplegit.rb

$ git checkout v0.1

.git/refs/tags/v0.1 "0c819c"

1

2

3

commit : a11bef

tag : 0c819c

tree : 1a738d

tree : fe8971

blob : a874b7

blob : a906cb

blob : a0a60a

README

Rakefile

lib

simplegit.rb

$ git checkout v0.1

.git/refs/tags/v0.1 "0c819c"

1

2

3

the commit history

blob

commit

treeC1}

branch

branch

branching and merging

C1

master

C0

C2 C3

experiment

HEAD

C1

master

C0

C2 C3

experimentC1

master

C0

C2 C3

C4

experiment

C5

T1

git checkout -b experiment

HEAD

C1

master

C0

C2 C3

experiment

C1

master

C0

C2 C3

C4

experiment

C5

T1

git commit

HEAD

C1

master

C0

C2 C3

experiment

C1

master

C0

C2 C3

C4

experiment

C5

T1

git commitgit commit

HEAD

C1

master

C0

C2 C3

experiment

C1

master

C0

C2 C3

C4

experiment

C5

T1

HEAD

git checkout master

C1

master

C0

C2 C3

C4

experiment

C5

T1

C1

master

C0

C2 C3

C4

experiment

C5

T1git commit

HEAD

C1

master

C0

C2 C3

C4

experiment

C5

T1

C1

master

C0

C2 C3

C4

experiment

C5

T1git tag -a ‘v1.1’

HEAD

C1

master

C0

C2 C3

C4

experiment

C5

T1

git checkout experimentgit commit

HEAD

C1C0

C2 C3

C4

experiment

C5

C6

masterT1

git checkout mastergit merge experiment

HEAD

remotes

C1

origin/master

C0 C2

masterC1

origin/master

C0 C2

master

C1

origin/master

C0 C2

masterC1

origin/master

C0 C2

master

C1

origin/master

C0 C2

master

C1

origin/master

C0 C2

master

git fetch originCL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

CL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

git fetch origin

CL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

git checkout -b tryidea

CL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

tryidea

CL3

CL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

tryidea

CL3

git merge origin/master origin/idea

CL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

tryidea

CL3

CL1

origin/master

C0 CL2

master

CR3CR1 CR4

origin/idea

CR2

remote workflow

public repo

local repo

local repo

public repo

internet

A B C

public repo

local repo

local repo

public repo

git push(ssh)

internet

A B C

A B C

public repo

local repo

local repo

public repo

git push(ssh)

git fetch(git)

internet

A B C

A B C

A B C

public repo

local repo

local repo

public repo

git push(ssh)

git fetch(git)

internet

A B C

A B C

A B C

D E F git commit

public repo

local repo

local repo

public repo

git push(ssh)

git fetch(git)

git push(ssh)

internet

A B C

A B C

A B C

D E F

A B C

D E F

public repo

local repo

local repo

public repo

git fetch(http)

git push(ssh)

git fetch(git)

git push(ssh)

internet

A B C

A B C

A B C

D E F

A B C

D E F

D E F

public repo

local repo

local repo

public repo

git fetch(http)

git push(ssh)

git fetch(git)

git push(ssh)

internet

A B C

A B C

A B C

D E F

A B C

D E F

D E FD E F

multiple remotes

developernick

developerjessica

my repo5ec

e4a4a7ce0 master

developernick

developerjessica

my repo5ec

e4a4a7ce0 master

commit

developernick

developerjessica

my repo5ec

e4a4a7ce0 master

tree

developernick

developerjessica

my repo5ec

e4a4a7ce0 master

blobs

schacon/project

developernick

developerjessica

"public"

my repo5ec

e4a4a7ce0 master

git push public

public/master

5ece4a

4a7ce0

schacon/project

developerjessica

"public"

my repo5ec

e4a4a7ce0 master

git clone (url)

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nick

schacon/project

developerjessica

"public"

my repo5ec

e4a4a7ce0 master

git commit

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f git clone (url)

5ece4a

4a7ce0developer

jessica

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09git commit

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09git push

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git remote add nick git://github.com/nickh/project.git

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick"

git remote add nick git://github.com/nickh/project.git

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git remote add nick git://github.com/nickh/project.git

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick"“nick”

git remote add nick git://github.com/nickh/project.git

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git remote add jess git://github.com/jessica/project.git

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

git remote add jess git://github.com/jessica/project.git

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git remote add jess git://github.com/jessica/project.git

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

git remote add jess git://github.com/jessica/project.git

“jess”

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git remote add jess git://github.com/jessica/project.git

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git fetch nick

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

c12ec524f nick/master

git fetch nick

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git fetch nick

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

c12ec524f nick/master

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git remote add jess git://github.com/jessica/project.git

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

git fetch jess

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git fetch jess

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git fetch nick

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

c12ec524f nick/master

schacon/project

"public"

my repo5ec

e4a4a7ce0 master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git fetch jess

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

schacon/project

"public"

my repo5ec

e4a4a7ce0

master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

b3bc63

git merge nick jess

schacon/project

"public"

my repo5ec

e4a4a7ce0

master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

git push public

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

b3bc63

e4aec524f

2fbdf74eaa09

c12

b3bc63

schacon/project

"public"

my repo5ec

e4a4a7ce0

master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

b3bc63

e4aec524f

2fbdf74eaa09

c12

b3bc63

schacon/project

"public"

my repo5ec

e4a4a7ce0

master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

b3bc63

e4aec524f

2fbdf74eaa09

c12

b3bc63

schacon/project

"public"

my repo5ec

e4a4a7ce0

master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

b3bc63

e4aec524f

2fbdf74eaa09

c12

b3bc63

schacon/project

"public"

my repo5ec

e4a4a7ce0

master

public/master

5ece4a

4a7ce0

5ece4a

4a7ce0developer

nickc12ec524f

5ece4a

4a7ce0developer

jessica2fbdf74ea

a09

5ece4a

4a7ce0nickh/project

c12ec524f

5ece4a

4a7ce0jessica/project

2fbdf74eaa09"nick" "jess"

ec524f nick/master

2fbdf74eaa09

jess/masterc12

b3bc63

e4aec524f

2fbdf74eaa09

c12

b3bc63

rebasing

C1

C2

local jessica

master

C1

masterC2

C1

C2

local jessica

master

git clone

C1

master

C2

C3

C4

C1

C2

C5

C6

local jessica

master git commit

git commit

C1

master

C2

C3

C4

C1

C2

local jessica

pack

master

git fetch jessC6

C5

C1

jess/master

C2

C3

C4

C5

C6

local

master

C1

jess/master

C2

C3

C4

C5

C6master

git merge

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C3

C4

C5

C6master

git rebase

C3'

C4'

C3

C4

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C5

C6

master

git rebase

C3'

C4'

C3

C4

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C5

C6

master

git rebase

C3'

C4'

C3

C4

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C5

C6

master

git rebase

1

2

C3'

C4'

C3

C4

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C5

C6

master

git rebase

1

2

C3'

C4'

C3

C4

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C5

C6

master

git rebase

C3'

C4'

C1

jess/master

C2

C3

C4

C5

C6

git merge

C7master

C1

jess/master

C2

C5

C6

master

git rebase

the treeish

the treeish

alternate ways to refer to objects or ranges of objects

Treeish

• full sha-1

• partial sha-1

• branch or tag name

• date spec

• ordinal spec

• carrot parent

• tilde spec

• tree pointer

• blob spec

• ranges

Full SHA1

6e453f523fa1da50ecb04431101112b3611c6a4d

Partial SHA16e453f523fa1da50ecb04431101112b3611c6a4d

6e453f523fa1da50

6e453

Branch, Remote or Tag Name

v1.0

master

origin/testing

Date Spec

master@{yesterday}

master@{1 month ago}

Ordinal Spec

master@{5}

5th prior value of ‘master’

Carrot Parent

master^2

2nd parent of ‘master’

Tilde Spec

master~2

2nd generation grandparent of ‘master’

Tree Pointer

master^{tree}

tree that ‘master’ points to

Blob Spec

master:/path/to/file

blob of that file in ‘master’ commit

Ranges

ce0e4..e4272

everything between two commits

Ranges

ce0e4..

everything since a commit

examples

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master^

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master^2

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master~2

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master^^^2master~2^2

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master^^^2master~2^2

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master^^^2master~2^2

ce0e4

master

5ec47 2f45e 4eadf 2fbb3 18cae

b3be1 a09c6 df2fa c36ae

jess/master

master~3..master^

local stuff

the index

Git Directoryconfig file

hooks

index

object database

references

index

index

working directory

repository

index

git add

git commit

index

working directory

repository

index

git add

git commit

index

working directory

repository

index

git add

git commit

what?

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:30

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:30

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:30

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:30

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:30

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD git wdir mtime fname

Object Directory Working DirectoryIndex

project/.git/index project/project/.git/objects

stage

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:30

git checkout

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

e4a

24f

e4a

24f file1

file2

1:30

1:30

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:31

vim file2

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:31

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:31

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:31

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

e4a

24f

stage

/file1

/file2

1:30

1:31

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

git add file2

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

git add file2

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

git add file2

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

git add file2

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

e4a

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

1ba

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

a3e

83d

git commit

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

1ba

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

a3e

83d

git commit

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

1ba

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

a3e

83d

git commit

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

1ba

24f

1ba

24f file1

file2

1:30

1:31

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:30

1:311ba

a3e

83d

git commit

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:32

1:321ba

a3e

83d

vim file1 file2 git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:32

1:321ba

a3e

83d

vim file1 file2 git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

24f

stage

/file1

/file2

1:32

1:321ba

a3e

83d

vim file1 file2 git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

git add file1

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

git add file1

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

git add file1

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

24f file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

git status

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

91b file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

1a7

6c5

git commit

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

91b file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

1a7

6c5

git commit

5ec

e4a

4a7

ce0

master

ec5

24f

c12

HEAD

Object Directory Working Directory

project/project/.git/objects

6d4

91b

1ba

91b file1

file2

1:32

1:32

git wdir mtime fname

Index

project/.git/index

1ba

91b

stage

/file1

/file2

1:32

1:321ba

a3e

83d

91b

1a7

6c5

How Do I Use Git?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

75%

35 min

12m How Do I Use Git?

152 Total Commands

43 Porcelain Commands

We’ll Cover Half

getting git

git.or.cz

git.or.cz

wgetmake

make install

yum install git-core

apt-get install git-core

port install git-core +svn

setup

git config --global user.name “Scott Chacon”

git config --global user.email “schacon@gmail.com”

1 Down

getting a repo

git clone

Git Protocols

ssh://

http[s]://

git://

file:///

rsync://

Git Protocols

ssh://

http[s]://

git://

file:///

rsync://

Git Protocols

ssh://

http[s]://

git://

file:///

rsync://

push

Git Protocols

ssh://

http[s]://

git://

file:///

rsync://

pull

git clone

git clone

git clone

git clone

initializing a repo

cd myproject

git init

git add .

git commit

5 Down

normal workflow

.gitignore

adding and committing

working directory

repository

index

git add

git commit

working directory

repository

index

git add

git commit

git log

git log --pretty

6 Down

git diff

git diff (treeish1) (treeish2)

git diff master^ > change.diff

git diff master^ > change.diff

patch -p1 < change.diff

git diff master^ > change.diff

patch -p1 < change.diff

git apply change.diffor

git and patches

Single Commit

git format-patch origin/master --stdout > story.patch

git am < story.patch

Multiple Commits

$ git format-patch -o patches origin$ git send-email --to list@email.com patches

$ git am mbox

Multiple Commits

$ git format-patch -o patches origin$ git send-email --to list@email.com patches

$ git am mbox

1 patch file per commitin this directory

example: patching rails

Patching Rails

git clone git://github.com/rails/rails.git

cd rails; (vim/emacs etc)

git format-patch origin/master --stdout > story.patch

upload story.patch to rails.lighthouseapp.com

Applying a Rails Patch

download story.patch from rails.lighthouseapp.com

git am < story.patch

11 Down

branch, merge, rebase

master

develop

topic

master

develop

topic

master

develop

topic

master

develop

topic

master

develop

topic

master

develop

topic

master

develop

topic

master

develop

topic

“production”

master

develop

topic

“production”

“trunk”

master

develop

topic

“production”

“trunk”convention!

branching workflow

normal development

want to try an idea

have to do a hotfix

merge idea into development

push to production

branching workflow

normal development

want to try an idea

have to do a hotfix

merge idea into development

push to production

C3

master

C0

develop

story95

C4

C1 C2

idea

branching workflow

normal development

want to try an idea

have to do a hotfix

merge idea into development

push to production

C3

master

C0

develop

story95

C4

C1 C2

idea

C3

master

C0

develop

story95

C4

C1 C2

idea

idea

C3

master

C0

develop

story95

C4

C1 C2

C5

C6

master

branching workflow

normal development

want to try an idea

have to do a hotfix

merge idea into development

push to production

idea

C3

master

C0

develop

story95

C4

C1 C2

C5

C6

master

branching workflow

normal development

want to try an idea

have to do a hotfix

merge idea into development

push to production

develop

C3

C0

story95

C4

C1 C2

C5

C6

master

branching workflow

normal development

want to try an idea

have to do a hotfix

merge idea into development

push to production

develop

C3

C0

story95

C4

C1 C2

C5

C6 C7

master

develop

C4C0

story95

C5

C1 C2

C6'C3

master

develop

C4C0

story95

C5

C1 C2

C6'C3

master

develop

C4C0

story95

C5

C1 C2

C6'C3

master

develop

C3

C0

story95

C4

C1 C2

C5

C6 C7

master

merge

rebasedevelop

C4C0

story95

C5

C1 C2

C6'C3

master

one more time now!

C3

master

C0

develop

story95

C4

C1 C2

idea

C3

master

C0

develop

story95

C4

C1 C2

idea

git checkout -b idea

idea

C3

master

C0

develop

story95

C4

C1 C2

C5

C6

master

git commit

idea

C3

master

C0

develop

story95

C4

C1 C2

C5

C6

master

git checkout mastergit commit

develop

C3

C0

story95

C4

C1 C2

C5

C6

master

git checkout ideagit merge developgit branch -d idea

develop

C3

C0

story95

C4

C1 C2

C5

C6 C7

master

git checkout mastergit merge develop

17 Down

sharing git

git clone git://github.com/schacon/simplegit2.git

distributed workflow

distributed workflowfetch, pull and push

fetch

pull

pull = fetch + merge

push

git push

We Know Em All!

review

• Local Commands

• git config

• git init

• git add

• git commit

• git status

• git tag

• git log

• Local Commands

• git config

• git init

• git add

• git commit

• git status

• git tag

• git log

• Branchy Commands

• git checkout

• git branch

• git merge

• git rebase

• Local Commands

• git config

• git init

• git add

• git commit

• git status

• git tag

• git log

• Branchy Commands

• git checkout

• git branch

• git merge

• git rebase

• Remotey Commands

• git remote

• git fetch

• git pull

• git clone

• git push

• Local Commands

• git config

• git init

• git add

• git commit

• git status

• git tag

• git log

• Branchy Commands

• git checkout

• git branch

• git merge

• git rebase

• Remotey Commands

• git remote

• git fetch

• git pull

• git clone

• git push

• Patchy Commands

• git diff

• git apply

• git format-patch

• git am

• Local Commands

• git config

• git init

• git add

• git commit

• git status

• git tag

• git log

• Branchy Commands

• git checkout

• git branch

• git merge

• git rebase

• Remotey Commands

• git remote

• git fetch

• git pull

• git clone

• git push

• Patchy Commands

• git diff

• git apply

• git format-patch

• git am

popular workflows

central repository model

developerdeveloper

developer

shared repositorydeveloper

developer

developer

developerdeveloper

developer

developer

shared repository

developer developer

git clone

developer

shared repository

developer developer

git push

developer

shared repository

developer developer

git push

developer

shared repository

developer developer

developer

shared repository

developer developer

git fetchgit merge

developer

shared repository

developer developer

git push

dictator and lieutenants model

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

git clone

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

git fetchgit merge

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

git fetchgit merge

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

git fetch; git merge

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

git push

developerdeveloper

dictator

developer

lieutenant

blessed repository

developer

lieutenant

git fetch

integration manager model

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

github.com/schacon/ticgit

/yob/ticgit /pope/ticgit

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

github.com/schacon/ticgit

/yob/ticgit /pope/ticgit“forks”

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git push

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git clone

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git push

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git fetchgit merge

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git push

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git fetchgit rebase / merge

developerpublic

developerpublic

integration manager

blessedrepository

developerprivate

developerprivate

git push

How Do I Deploy with Git?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

4m How Do I Deploy with Git?15%

6 min

capistrano + git

deploy.rb

deploy.rb

deploy.rb

other cap options

set :branch, "master"

set :git_shallow_clone, 1

set :git_enable_submodules, 1

ruby + git

ruby + git

grit

git gem

git-ruby

ruby + git

grit

git gem

git-ruby

github.com/schacon/ruby-git

Where Can I Learn More?

2m Who is Scott?

What is Git?

How Does Git Work?

How Do I Use Git?

2m This Slide

3m

20m

12m

How Do I Deploy with Git?4m

Where Can I Learn More?2m

75%

35 min

15%

6 min

10%

4 min

2m Where Can I Learn More?

15%

6 min

Resourcesgit.or.cz

gitcasts.com

del.icio.us/popular/git

#git / #github on IRC

peepcode - git book and screencast

schacon@gmail.com

me. here.

thats it!

thats it!

gitcasts.com/git-talknotes, these slides, etc

thats it!

gitcasts.com/git-talknotes, these slides, etc

git.or.cz

gitcasts.com

del.icio.us/popular/git

#git / #github on IRC

peepcode

schacon@gmail.com

Recommended