Scott Chacon Simple Storage Service

Report 3 Downloads 76 Views
Getting Git Scott Chacon

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

Who Is Scott? Introducing myself...

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

Scott Anthony Chacon

github.com/schacon

www.gitcasts.com

Huge Flat Screens 3D Cameras Xen Rails Git

jepoirrier@flickr

me

introduce yourself

introduce yourself and your sweet projects...

why is scott here?

What is Git?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

git is

git is directory content management system

git is tree history storage system

git is stupid content tracker

git is a toolkit

the “plumbing”

the “porcelain”

git is not subversion!

forget subversion!

not an evolution

not an evolution rcs

cvs

svn

git

not an evolution rcs

cvs

svn

git

not an evolution rcs

cvs

svn

git

source control taxonomy

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

source control taxonomy delta storage

C1

C2

file A

!1

C3

C5

!2

file B

DAG storage

C4

!1

!2

file C

!1

!2

C1

C2

C3

C4

C5

A

A1

A1

A2

A2

B

B

B

B1

B2

C

C1

C2

C2

C3

!3

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazzar

controltaxonomy taxonomy sourcesource control

delta storage

DAG storage

local

rcs

centralized

cvs

svn

distributed

darcs

mercurial

local

cp -r

perforce

time machine

centralized bitkeeper distributed

git

bazaar bazzar

How Does Git Work?

?

How Does Git Work?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

git

git directory

git directory .git

git directory .git GIT_DIR

Git Directory config file hooks index object database references

object database

object database content

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

object database content

“header”

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

object database content new_content = type + ’ ‘ + content.size + \0 + content sha = Digest::SHA1.hexdigest(new_content)

object database content new_content = type + ’ ‘ + content.size + \0 + content sha = Digest::SHA1.hexdigest(new_content) “824aed035c0aa75d64c...”

object database content new_content = type + ’ ‘ + content.size + \0 + content sha = Digest::SHA1.hexdigest(new_content) “824aed035c0aa75d64c...” compressed = zlib::deflate(new_content)

object database content new_content = type + ’ ‘ + content.size + \0 + content sha = Digest::SHA1.hexdigest(new_content) “824aed035c0aa75d64c...” compressed = zlib::deflate(new_content) path = “.git/objects/82/4aed035c0aa75d64c...”

object database content new_content = type + ’ ‘ + content.size + \0 + content sha = Digest::SHA1.hexdigest(new_content) “824aed035c0aa75d64c...” compressed = zlib::deflate(new_content) path = “.git/objects/82/4aed035c0aa75d64c...” File.open(path, ‘w’) {|f| f.write(compressed)}

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

“loose” format

sha = Digest::SHA1.hexdigest(new_content) “824aed035c0aa75d64c...” compressed = zlib::deflate(new_content) path = “.git/objects/82/4aed035c0aa75d64c...” File.open(path, ‘w’) {|f| f.write(compressed)}

object database git gc

object database git gc same file with minor differences

object database git gc same file with minor differences .git/objects/82/4aed035c0aa75d64c... .git/objects/1d/c9cbcb76cbb80fce1... .git/objects/63/874f37013c1740acd... .git/objects/04/fb8aee105e6e445e8... .git/objects/45/b983be36b73c0788d... .git/objects/f1/032eed02413a1145c...

object database git gc same file with minor differences .git/objects/82/4aed035c0aa75d64c... .git/objects/1d/c9cbcb76cbb80fce1... .git/objects/63/874f37013c1740acd... .git/objects/04/fb8aee105e6e445e8... .git/objects/45/b983be36b73c0788d... .git/objects/f1/032eed02413a1145c... .git/objects/pack/pack-999727..9f600.pack .git/objects/pack/pack-999727..9f600.idx

object database git gc same file with minor differences .git/objects/82/4aed035c0aa75d64c... .git/objects/1d/c9cbcb76cbb80fce1... .git/objects/63/874f37013c1740acd... .git/objects/04/fb8aee105e6e445e8... .git/objects/45/b983be36b73c0788d... .git/objects/f1/032eed02413a1145c... .git/objects/pack/pack-999727..9f600.pack .git/objects/pack/pack-999727..9f600.idx

object database git gc same file with minor differences

“packed” format

.git/objects/82/4aed035c0aa75d64c... .git/objects/1d/c9cbcb76cbb80fce1... .git/objects/63/874f37013c1740acd... .git/objects/04/fb8aee105e6e445e8... .git/objects/45/b983be36b73c0788d... .git/objects/f1/032eed02413a1145c...

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

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 blob commit

tree

object database blob

tree

commit

tag

object database blob

object database blob Working Directory

Git Directory

./

Rakele

blob : a874b7

README

blob : a906cb

lib/

simplegit.rb

blob : a0a60a

object database blob : a906cb

{ zlib::deflate Zlib::Inflate

blob [content size]\0 SimpleGit Ruby Library ====================== This library calls git commands and returns the output. Author : Scott Chacon

object database blob : a906cb

{ zlib::deflate Zlib::Inflate

blob [content size]\0 SimpleGit Ruby Library ======================

content

This library calls git commands and returns the output. Author : Scott Chacon

object database blob : a906cb

{ zlib::deflate Zlib::Inflate

header

blob [content size]\0 SimpleGit Ruby Library ======================

content

This library calls git commands and returns the output. Author : Scott Chacon

object database blob : a906cb

header

{

compress

zlib::deflate Zlib::Inflate

blob [content size]\0 SimpleGit Ruby Library ======================

content

This library calls git commands and returns the output. Author : Scott Chacon

object database compress header

blob : a906cb

{

object

zlib::deflate Zlib::Inflate

blob [content size]\0 SimpleGit Ruby Library ======================

content

This library calls git commands and returns the output. Author : Scott Chacon

object database blob

tree

commit

tag

object database tree

object database tree Working Directory

Git Directory

./

Rakele

blob : a874b7

README

blob : a906cb

lib/

simplegit.rb

blob : a0a60a

object database tree Working Directory

Git Directory tree : 1a738d

./

Rakele

blob : a874b7

README

blob : a906cb

lib/

tree : fe8971

simplegit.rb

blob : a0a60a

object database

{

tree : 1a738d

zlib::deflate Zlib::Inflate

tree [content size]\0 100644 blob a906cb 100644 blob a874b7 040000 tree fe8971

README Rakefile lib

object database

{

tree : 1a738d

zlib::deflate Zlib::Inflate

tree [content size]\0 100644 blob a906cb 100644 blob a874b7 040000 tree fe8971

README Rakefile lib

“inode” info

filename

object database

{

tree : 1a738d

zlib::deflate Zlib::Inflate

tree [content size]\0 100644 blob a906cb 100644 blob a874b7 040000 tree fe8971

mode

README Rakefile lib

type “block pointer”

object database blob

tree

commit

tag

object database

commit

HEAD

object database branch

commit commit

tree

tree

blob

tree

blob

blob

object database

{

commit : e1b3ec

Zlib::Inflate zlib::deflate

commit [content size]\0 tree e1b3ec parent a11bef author Scott Chacon <[email protected]> 1205624433 committer Scott Chacon <[email protected]> 1205624433 my second commit, which is better than the first

object database

{

commit : e1b3ec

Zlib::Inflate zlib::deflate

commit [content size]\0 tree e1b3ec parent a11bef author Scott Chacon <[email protected]> 1205624433 committer Scott Chacon <[email protected]> 1205624433 my second commit, which is better than the first

object database

{

commit : e1b3ec

Zlib::Inflate zlib::deflate

commit [content size]\0 tree e1b3ec parent a11bef author Scott Chacon <[email protected]> 1205624433 committer Scott Chacon <[email protected]> 1205624433 my second commit, which is better than the first

object database

{

commit : e1b3ec

Zlib::Inflate zlib::deflate

commit [content size]\0 tree e1b3ec parent a11bef author Scott Chacon <[email protected]> 1205624433 committer Scott Chacon <[email protected]> 1205624433 my second commit, which is better than the first

object database

{

commit : e1b3ec

Zlib::Inflate zlib::deflate

commit [content size]\0 tree e1b3ec parent a11bef author Scott Chacon <[email protected]> 1205624433 committer Scott Chacon <[email protected]> 1205624433 my second commit, which is better than the first

remote

branch

object database commit

tree

blob

tag

object database blob

tree

commit

tag

object database

tag

object database HEAD

remote

tag

branch

commit

tree

blob

tag

object database

{

tag : 0c819c

zlib::deflate Zlib::Inflate

tag [content size]\0 object 0576fa type commit tag v0.1 tagger Scott Chacon <[email protected]> 1205624655 this is my v0.1 tag

object database

{

tag : 0c819c

zlib::deflate Zlib::Inflate

tag [content size]\0 object 0576fa type commit tag v0.1 tagger Scott Chacon <[email protected]> 1205624655 this is my v0.1 tag

object database

{

tag : 0c819c

zlib::deflate Zlib::Inflate

tag [content size]\0 object 0576fa type commit tag v0.1 tagger Scott Chacon <[email protected]> 1205624655 this is my v0.1 tag

object database

{

tag : 0c819c

zlib::deflate Zlib::Inflate

tag [content size]\0 object 0576fa type commit tag v0.1 tagger Scott Chacon <[email protected]> 1205624655 this is my v0.1 tag

object database

{

tag : 0c819c

zlib::deflate Zlib::Inflate

tag [content size]\0 object 0576fa type commit tag v0.1 tagger Scott Chacon <[email protected]> 1205624655 this is my v0.1 tag

object database blob

tree

commit

tag

object database blob

tree

commit

tag

immutable

object database blob

tree

commit

tag

immutable can’t be muted

Git Directory config file hooks index object database references

references

references lightweight, movable pointers to a commit remote

HEAD

branch

commit

tree

blob

tag

references lightweight, movable pointers to a commit remote

HEAD

branch

commit

tree

blob

stored in .git/refs/* as simple files tag

references HEAD

remote

branch

commit

tree

blob

tag

the object model

HEAD

branch

commit

tree

tree

blob

tree

blob

blob

HEAD

branch

commit

tree

tree

blob

tree

blob

blob

HEAD

branch

commit

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob

HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob

HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob

HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob

HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob

HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob

1

$ git checkout v0.1

2

.git/refs/tags/v0.1

3

tag : 0c819c

"0c819c"

commit : a11bef

tree : 1a738d

Rakefile

blob : a874b7

README

blob : a906cb

lib

tree : fe8971

simplegit.rb

blob : a0a60a

1

$ git checkout v0.1

2

.git/refs/tags/v0.1

3

tag : 0c819c

"0c819c"

commit : a11bef

tree : 1a738d

Rakefile

blob : a874b7

README

blob : a906cb

lib

tree : fe8971

simplegit.rb

blob : a0a60a

1

$ git checkout v0.1

2

.git/refs/tags/v0.1

3

tag : 0c819c

"0c819c"

commit : a11bef

tree : 1a738d

Rakefile

blob : a874b7

README

blob : a906cb

lib

tree : fe8971

simplegit.rb

blob : a0a60a

1

$ git checkout v0.1

2

.git/refs/tags/v0.1

3

tag : 0c819c

"0c819c"

commit : a11bef

tree : 1a738d

Rakefile

blob : a874b7

README

blob : a906cb

lib

tree : fe8971

simplegit.rb

blob : a0a60a

1

$ git checkout v0.1

2

.git/refs/tags/v0.1

3

tag : 0c819c

"0c819c"

commit : a11bef

tree : 1a738d

Rakefile

blob : a874b7

README

blob : a906cb

lib

tree : fe8971

simplegit.rb

blob : a0a60a

the commit history

branch

commit

tree

blob

}

branch

C1

branching and merging

HEAD

master

C0

experiment

C1

C2

C3

C4

C3 C0

master

C5 C1

experiment C2

HEAD

experiment

git checkout -b experiment C3

2

T1

master

master

experiment

git commit C0

C4 C1

C3

C5 C2

experiment

HEAD

C3

T1

master

C1C0

C1

C2

master experiment

git commit git commit

C4

C3 C2

C5 C3

experiment

HEAD

HEAD

T1

master

C1C0

C1

C2

git checkout master master experiment

C4

C3 C2

C5 C3

experiment

T1 git commit

master T1

master

HEAD

C1 C0

C1

C2

C4

C3 C2

C4

C5 C3

C5

experiment

experiment

git tag -a ‘v1.1’

T1

master T1

master

HEAD

C1 C0

C1

C2

C4

C3 C2

C4

C5 C3

C5

experiment

experiment

T1

C0

C1

master

C4

C2

git checkout experiment git commit

C3

C5

experiment

HEAD

HEAD

C0

C1

C2

git checkout master git merge experiment

C3

T1

master

C4

C6

C5

experiment

remotes

master

origin/master C2

C0

master

C1

C2

master

origin/master C2

C0

master

C1

C2

aster origin/master

C0C1

master

C1C2

master

C2

origin/idea

CR2

C0

origin/master

CR1

CR3

CL1

CL2

master

CR4

git fetch origin

origin/idea

CR2

C0

origin/master

CR1

CR3

CL1

CL2

master

CR4

git fetch origin

in/idea

CR2

origin/idea

origin/master CR2

origin/master

CR3

CR1 CR4

CR3

CR4

C0 CL2

CL1

CL2

CL3

master

tryidea

master

git checkout -b tryidea

origin/idea

CR2

C0

origin/master

CR1

CR3

CR4

CL1

CL2

CL3

master

tryidea

git merge origin/master origin/idea

origin/idea

CR2

C0

origin/master

CR1

CR3

CR4

CL1

CL2

CL3

master

tryidea

origin/idea

CR2

C0

origin/master

CR1

CR3

CL1

CL2

master

CR4

remote workflow

local repo

public repo

public repo

internet

local repo A

B

C

local repo

public repo A

B

public repo

C

internet git push (ssh)

local repo A

B

C

local repo

git fetch (git)

A

B

C

public repo A

B

public repo

C

internet git push (ssh)

local repo A

B

C

local repo

git fetch (git)

A

B

C

D

E

F

public repo A

B

git commit

public repo

C

internet git push (ssh)

local repo A

B

C

local repo

git fetch (git)

A

B

C

D

E

F

public repo A

B

git push (ssh)

public repo

C

internet git push (ssh)

local repo A

B

C

A

B

C

D

E

F

local repo

git fetch (git)

A

B

C

D

E

F

public repo A

B

git push (ssh)

public repo

C

internet git push (ssh)

A

B

C

D

E

F

git fetch (http)

local repo A

B

C

D

E

F

local repo

git fetch (git)

A

B

C

D

E

F

public repo

internet

git push (ssh)

public repo

A

B

C

A

B

C

D

E

F

D

E

F

git push (ssh)

git fetch (http)

local repo A

B

C

D

E

F

multiple remotes

developer nick

developer jessica

ce0

my repo

e4a

4a7

5ec

master

developer nick

developer jessica

commit ce0

my repo

e4a

4a7

5ec

master

developer nick

developer jessica

tree ce0

my repo

e4a

4a7

5ec

master

developer nick

developer jessica

blobs ce0

my repo

e4a

4a7

5ec

master

developer nick

developer jessica

schacon/ project

ce0

4a7

5ec

4a7

5ec

e4a

"public"

git push public ce0

my repo

e4a

master public/master

developer nick

ce0

4a7

5ec

developer jessica

e4a

git clone (url) schacon/ project

ce0

4a7

5ec

4a7

5ec

e4a

"public"

ce0

my repo

e4a

master public/master

developer nick

ce0

4a7

5ec

ec5

c12

developer jessica

e4a 24f

git commit schacon/ project

ce0

4a7

5ec

4a7

5ec

e4a

"public"

ce0

my repo

e4a

master public/master

developer nick

ce0

4a7

5ec

e4a 24f

ec5

c12

git clone (url)

schacon/ project

ce0

4a7

5ec

4a7

5ec

developer jessica

e4a

"public"

ce0

my repo

e4a

master public/master

ce0 e4a

4a7

5ec

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

git commit

schacon/ project

ce0

4a7

5ec

4a7

5ec

"public"

my repo

e4a

master public/master

4a7

5ec

df7

2fb

e4a 4ea a09

e4a

ce0

ce0

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

git push

nickh/ project

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

e4a

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea

jessica/ project

ce0 e4a 4ea a09

ce0

4a7

a09

"public"

my repo

ce0

5ec

master public/master

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

jessica/ project

"public"

e4a 4ea a09

ce0

my repo

ce0

e4a

4a7

5ec

master public/master

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

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick" “nick”

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

jessica/ project

"public"

e4a 4ea a09

ce0

my repo

ce0

e4a

4a7

5ec

master public/master

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

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

"public"

"jess"

ce0

my repo

jessica/ project

e4a

4a7

5ec

ce0 e4a 4ea a09

master public/master

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

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

"jess" “jess”

"public"

ce0

my repo

jessica/ project

e4a

4a7

5ec

ce0 e4a 4ea a09

master public/master

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

5ec c12

schacon/ project developer "public" nick

ce0 e4a ce0

4a7 4a7

5ec 5ec

e4a 24f

ec5

c12

jessica/ project

"jess"

ce0

4a7

5ec

df7

2fb

e4a 4ea a09

developer jessica

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ my repo project

ce0

4a7

5ec

e4a 24f

ec5

c12

master

schacon/ public/master project

ce0

4a7

5ec

e4a

nick/master

"public"

"nick"

jessica/ project

"jess"

ce0 e4a 4ea a09

git fetch nick ce0

my repo

e4a

4a7

5ec

master public/master

git fetch nick

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

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

"public"

"jess"

ce0

my repo

jessica/ project

4a7

5ec

e4a 24f

master public/master

ec5

c12

git fetch nick

nick/master

ce0 e4a 4ea a09

nickh/ project developer nick

ce0

4a7

5ec

e4a 24f

ec5

e4a 24f

ec5

c12

schacon/ project

4a7

5ec

df7

2fb

ce0

4a7

5ec

master

my repo jessica/ project

e4a ce0

4a7

5ec

public/m

24f e4a

ec5

c12

nick/mas

4ea

df7

2fb

jess/mas

"jess"

a09

"public" developer jessica

"nick"

c12

jessic proje

e4a ce0 e4a 4ea

"jess

a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

"public"

git fetch jess ce0

my repo

4a7

5ec

e4a 24f

master master public/master public/master

ec5

c12

nick/master

fetch nick gitgitfetch jess

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

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

"public"

"jess"

ce0

my repo

jessica/ project

4a7

5ec

e4a

master public/master

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

git fetch jess

ce0 e4a 4ea a09

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

ce0

4a7

5ec

e4a

"public"

"jess"

ce0

my repo

git merge nick jess

jessica/ project

4a7

5ec

e4a

public/master

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

c63

b3b

master

ce0 e4a 4ea a09

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

ce0

4a7

5ec

e4a 24f

ec5

c12

"nick"

schacon/ project

"public"

my repo

ce0

4a7

5ec

e4a

jessica/ project

24f

ec5

c12

4ea

df7

2fb

a09

c63

b3b

ce0

4a7

5ec

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

c63

b3b

master

"jess"

e4a

public/master

git push public

ce0 e4a 4ea a09

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

"public"

my repo

ce0

4a7

5ec

e4a

jessica/ project

24f

ec5

c12

4ea

df7

2fb

a09

c63

b3b

ce0

4a7

5ec

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

c63

b3b

master

"jess"

e4a

public/master

ce0 e4a 4ea a09

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

"public"

my repo

ce0

4a7

5ec

e4a

jessica/ project

24f

ec5

c12

4ea

df7

2fb

a09

c63

b3b

ce0

4a7

5ec

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

c63

b3b

master

"jess"

e4a

public/master

ce0 e4a 4ea a09

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

"public"

my repo

ce0

4a7

5ec

e4a

jessica/ project

24f

ec5

c12

4ea

df7

2fb

a09

c63

b3b

ce0

4a7

5ec

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

c63

b3b

master

"jess"

e4a

public/master

ce0 e4a 4ea a09

developer nick

ce0

4a7

5ec

developer jessica

e4a 24f

ec5

c12

ce0

4a7

5ec

df7

2fb

4a7

5ec

df7

2fb

e4a 4ea a09

nickh/ project

"nick"

ce0

4a7

5ec

e4a 24f

ec5

c12

schacon/ project

"public"

my repo

ce0

4a7

5ec

e4a

jessica/ project

24f

ec5

c12

4ea

df7

2fb

a09

c63

b3b

ce0

4a7

5ec

24f

ec5

c12

nick/master

4ea

df7

2fb

jess/master

a09

c63

b3b

master

"jess"

e4a

public/master

ce0 e4a 4ea a09

rebasing

local

master

jessica

C2

C1

local

master

jessica

C2

C2

master

git clone C1

C1

local

master

jessica

C4

C6

C3

C5

C2

C2

C1

C1

master

git commit git commit

local

master

jessica

C4

C6 pack

C3

C5

C2

C2

C1

C1

master

git fetch jess

local

master

C4

C6

C3

C5

C2

C1

jess/master

git merge

master

C4

C6

C3

C5

C2

C1

jess/master

git merge master

C7

C4

C6

C3

C5

C2

C1

jess/master

git rebase

git merge master

C7

C4

C6

C3

C5

jess/master

master

C4

C6

C3

C5

C2

C2

C1

C1

jess/master

git rebase

git merge master

master

C7

C4'

C3'

C4

C6

C3

C5

jess/master

C4

C6

C3

C5

C2

C2

C1

C1

jess/master

git rebase

git merge master

master

C7

C4'

C3'

C4

C6

C3

C5

jess/master

C4

C6

C3

C5

C2

C2

C1

C1

jess/master

git rebase

git merge master

master

C7

C4

C4'

C3'

C6

jess/master

C4

C6

C3

C5

2

C3

C5 1

C2

C2

C1

C1

jess/master

git rebase

git merge master

master

C7

C4'

C3'

C4

C6

C3

C5

jess/master

2 1

C4

C6

C3

C5

C2

C2

C1

C1

jess/master

git rebase

git merge master

master

C7

C4'

C3'

C4

C6

C3

C5

jess/master

C4

C6

C3

C5

C2

C2

C1

C1

jess/master

git rebase

git merge

master

master

C7

C4'

C3'

C4

C6

C3

C5

jess/master

C6

C5

C2

C2

C1

C1

jess/master

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 SHA1 6e453f523fa1da50ecb04431101112b3611c6a4d 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

5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master^

5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master^2

5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master~2

5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master^^^2 master~2^2 5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master^^^2 master~2^2 5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master^^^2 master~2^2 5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

master~3..master^

5ec47

b3be1

a09c6

df2fa

c36ae

ce0e4

2f45e

4eadf

2fbb3

jess/master

18cae

master

local stuff

the index

Git Directory config file hooks index object database references

index

index working directory

git add index

git commit repository

index working directory

git add index

git commit repository

index working directory

git add index

git commit repository

what?

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

project/.git/index

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:30

/file2

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:30

/file2

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:30

/file2

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:30

/file2

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:30

/file2

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:30

/file2

project/.git/index

git checkout

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

e4a

1:30 file2

1:31

/file2

project/.git/index

vim file2

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

1ba

1:31 file2

1:31

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

1ba

1:31 file2

1:31

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

1ba

1:31 file2

1:31

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

e4a

1ba

1:31 file2

1:31

/file2

project/.git/index

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

1ba

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git add file2

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

1ba

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git add file2

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

1ba

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git add file2

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

1ba

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git add file2

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

1ba

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

4a7

ec5

ce0

e4a

24f

1ba

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

e4a

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

1ba

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git commit

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

1ba

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git commit

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

1ba

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git commit

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

24f

1:30 file1

1:30

/file1

1ba

1ba

1ba

1:31 file2

1:31

/file2

project/.git/index

git commit

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

vim file1 file2 git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

vim file1 file2 git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

24f

24f

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

vim file1 file2 git status

project/

Object Directory

Index

HEAD

git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

91b

24f

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git add file1

project/

Object Directory

Index

HEAD

git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

91b

24f

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git add file1

project/

Object Directory

Index

HEAD

git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

91b

24f

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git add file1

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

91b

24f

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

91b

24f

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

4a7

ec5

a3e

24f

1ba

ce0

e4a

project/.git/objects

91b

24f

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git status

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

6c5

4a7

ec5

a3e

1a7

24f

1ba

91b

ce0

e4a

project/.git/objects

91b

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git commit

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

6c5

4a7

ec5

a3e

1a7

24f

1ba

91b

ce0

e4a

project/.git/objects

91b

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

git commit

project/

Object Directory HEAD

Index git

stage wdir

mtime

Working Directory fname

master

5ec

c12

83d

6c5

4a7

ec5

a3e

1a7

24f

1ba

91b

ce0

e4a

project/.git/objects

91b

91b

91b

1:32 file1

1:32

/file1

1ba

1ba

6d4

1:32 file2

1:32

/file2

project/.git/index

project/

How Do I Use Git?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

152 Total Commands

43 Porcelain Commands

We’ll Cover Half

getting git

git.or.cz

git.or.cz wget make 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 “[email protected]

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 pull

ssh:// http[s]:// git:// file:/// rsync://

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

git add index

git com repository

working directory

git add index

git commit repository

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 or

git apply change.diff

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 [email protected] patches $ git am mbox

Multiple Commits 1 patch file per commit in this directory $ git format-patch -o patches origin $ git send-email --to [email protected] patches $ git am mbox

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”

convention! “trunk”

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

master

C0

C3

C1

C2

C4

develop

story95 idea

branching workflow normal development want to try an idea have to do a hotfix merge idea into development push to production

master

C0

C3

C1

C2

C4

develop

story95 idea

master

C0

C3

C1

C2

C4

develop

story95 idea

master

master

C0

C6

C3

C1

C2

story95

C4

C5

develop

idea

branching workflow normal development want to try an idea have to do a hotfix merge idea into development push to production

master

master

C0

C6

C3

C1

C2

story95

C4

C5

develop

idea

branching workflow normal development want to try an idea have to do a hotfix merge idea into development push to production

master

C0

C6

C3

C1

C2

story95

C4

C5

develop

branching workflow normal development want to try an idea have to do a hotfix merge idea into development push to production

master

C0

C6

C3

C1

C2

story95

C7

C4

C5

develop

master

C0

C3

C4

C5

C6'

develop

C1

C2

story95

master

C0

C3

C4

C5

C6'

develop

C1

C2

story95

master

C0

C3

C4

C5

C6'

develop

C1

C2

story95

master

C0

C6

C7

merge C3

C1

C4

C2

C5

develop

story95

master

rebase

C0

C3

C4

C5

C6'

develop

C1

C2

story95

one more time now!

master

C0

C3

C1

C2

C4

develop

story95 idea

master

C0

C3

C1

C2

C4

develop

story95 idea

git checkout -b idea

master

master

C0

C6

C3

C1

C2

C4

C5

develop

idea

story95

git commit

master

master

C0

C6

C3

C1

C2

C4

C5

develop

idea

story95

git checkout master git commit

master

C0

C6

C3

C1

C2

story95

C4

C5

develop

git checkout idea git merge develop git branch -d idea

master

C0

C6

C3

C1

C2

C7

C4

C5

develop

story95

git checkout master git merge develop

17 Down

sharing git

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

distributed workflow

distributed workflow fetch, 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

developer

developer developer

developer shared repository developer

developer

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 fetch git merge

developer

shared repository

developer

developer

git push

developer

dictator and lieutenants model

dictator

blessed repository

lieutenant lieutenant

developer

developer

developer

developer

dictator

blessed repository

lieutenant lieutenant

developer

developer

developer

git clone

developer

dictator

blessed repository

lieutenant lieutenant

developer

developer

git fetch git merge

developer

developer

dictator

blessed repository

lieutenant lieutenant

developer

developer

developer

git fetch git merge

developer

git fetch; git merge dictator

blessed repository

lieutenant lieutenant

developer

developer

developer

developer

git push dictator

blessed repository

lieutenant lieutenant

developer

developer

developer

developer

dictator

blessed repository

lieutenant lieutenant

developer

developer

developer

git fetch

developer

integration manager model

blessed repository

integration manager

developer public

developer public

developer private

developer private

/schacon/ticgit blessed repository

integration manager

github.com /yob/ticgit

/pope/ticgit

developer public

developer public

developer private

developer private

/schacon/ticgit blessed repository

integration manager

github.com “forks” /yob/ticgit /pope/ticgit developer public

developer public

developer private

developer private

blessed repository

integration manager

git push

developer public

developer public

developer private

developer private

blessed repository

integration manager

developer public

developer public

developer private

developer private

git clone

blessed repository

integration manager

developer public

developer public

developer private

developer private

git push

blessed repository

integration manager

developer public

developer public

developer private

developer private

git fetch git merge

blessed repository

integration manager

developer public

developer public

developer private

developer private

git push

blessed repository

integration manager

developer public

developer public

developer private

developer private

git fetch git rebase / merge

blessed repository

integration manager

git push

developer public

developer public

developer private

developer private

How Do I Deploy with Git?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

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?

10% 4 min

2m

This Slide

2m

Who is Scott?

3m

What is Git?

20m

How Does Git Work?

12m

How Do I Use Git?

75% 35 min

15% 6 min

4m

How Do I Deploy with Git?

2m

Where Can I Learn More?

Resources git.or.cz gitcasts.com del.icio.us/popular/git #git / #github on IRC peepcode - git book and screencast [email protected] me. here.

thats it!

thats it!

gitcasts.com/git-talk notes, these slides, etc

thats it!

gitcasts.com/git-talk notes, these slides, etc

git.or.cz gitcasts.com

del.icio.us/popular/git #git / #github on IRC

peepcode [email protected]