You are on page 1of 523

Getting Git

Scott Chacon
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
Who Is Scott?
Introducing myself...
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
2m Where Can I Learn More?
Scott Anthony Chacon
github.com/schacon
www.gitcasts.com
3D Cameras
Huge Xen
Rails
Git
Flat Screens
jepoirrier@flickr
me
introduce yourself
introduce yourself
and your sweet projects...
why is scott here?
What is Git?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
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
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
source control taxonomy
C1 C2 C3 C4 C5

file A !1 !2
delta
storage
file B !1 !2

file C !1 !2 !3

C1 C2 C3 C4 C5

DAG A A1 A1 A2 A2

storage
B B B B1 B2

C C1 C2 C2 C3
sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazzar


sourcesource
control
controltaxonomy
taxonomy

local rcs

delta
centralized cvs svn perforce
storage

distributed darcs mercurial

time
local cp -r
machine

DAG
centralized
storage
bitkeeper

distributed git bazaar


bazzar
How Does
Git Work?
?

How Does
Git Work?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
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

“loose” format
+ 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
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 tree

commit
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

header
{ 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

compress

header
{ 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
object blob : a906cb

compress

header
{ 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
README
Rakefile
040000 tree fe8971 lib
object database
tree : 1a738d

{ zlib::deflate
Zlib::Inflate

tree [content size]\0

100644 blob a906cb


100644 blob a874b7
README
Rakefile
040000 tree fe8971 lib

“inode” info filename


object database
tree : 1a738d

{ zlib::deflate
Zlib::Inflate

tree [content size]\0

100644 blob a906cb


100644 blob a874b7
README
Rakefile
040000 tree fe8971 lib

mode 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

{
tree e1b3ec
parent a11bef
zlib::deflate
Zlib::Inflate

commit [content size]\0

author Scott Chacon


<schacon@gmail.com> 1205624433
committer Scott Chacon
<schacon@gmail.com> 1205624433

my second commit, which is better than


the first
object database
commit : e1b3ec

{
tree e1b3ec
parent a11bef
zlib::deflate
Zlib::Inflate

commit [content size]\0

author Scott Chacon


<schacon@gmail.com> 1205624433
committer Scott Chacon
<schacon@gmail.com> 1205624433

my second commit, which is better than


the first
object database
commit : e1b3ec

{
tree e1b3ec
parent a11bef
zlib::deflate
Zlib::Inflate

commit [content size]\0

author Scott Chacon


<schacon@gmail.com> 1205624433
committer Scott Chacon
<schacon@gmail.com> 1205624433

my second commit, which is better than


the first
object database
commit : e1b3ec

{
tree e1b3ec
parent a11bef
zlib::deflate
Zlib::Inflate

commit [content size]\0

author Scott Chacon


<schacon@gmail.com> 1205624433
committer Scott Chacon
<schacon@gmail.com> 1205624433

my second commit, which is better than


the first
object database
commit : e1b3ec

{
tree e1b3ec
parent a11bef
zlib::deflate
Zlib::Inflate

commit [content size]\0

author Scott Chacon


<schacon@gmail.com> 1205624433
committer Scott Chacon
<schacon@gmail.com> 1205624433

my second commit, which is better than


the first
remote branch tag

object database
commit

tree

blob
object database

blob tree

commit tag
object database

tag
object database
HEAD

remote tag
branch tag

commit

tree

blob
object database
tag : 0c819c

{ zlib::deflate
Zlib::Inflate

tag [content size]\0

object 0576fa
type commit
tag v0.1
tagger Scott Chacon
<schacon@gmail.com> 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
<schacon@gmail.com> 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
<schacon@gmail.com> 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
<schacon@gmail.com> 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
<schacon@gmail.com> 1205624655

this is my v0.1 tag


object database

blob tree

commit tag
object database

blob tree
immutable
commit tag
object database

blob tree
immutable
commit tag
can’t be muted
Git Directory
config file
hooks
index
object database
references
references
references
lightweight, movable HEAD
pointers to a commit
remote branch tag

commit

tree

blob
references
lightweight, movable HEAD
stored in .git/refs/*
pointers to a commit as simple files
remote branch tag

commit

tree

blob
references
HEAD

remote branch tag

commit

tree

blob
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

blob
tree blob tree

tree blob tree

blob blob
HEAD

tag branch

commit commit commit

tree tree tree

blob
tree blob tree

tree blob tree

blob blob
HEAD

tag branch

commit commit commit

tree tree tree

blob
tree blob tree

tree blob tree

blob blob
HEAD

tag branch

commit commit commit

tree tree tree

blob
tree blob tree

tree blob tree

blob blob
HEAD

tag branch

commit commit commit

tree tree tree

blob
tree blob tree

tree blob tree

blob blob
HEAD

tag branch

commit commit commit

tree tree tree

blob
tree blob tree

tree blob tree

blob blob
1 $ git checkout v0.1

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

3 tag : 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 "0c819c"

3 tag : 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 "0c819c"

3 tag : 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 "0c819c"

3 tag : 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 "0c819c"

3 tag : 0c819c

commit : a11bef

tree : 1a738d

Rakefile blob : a874b7

README blob : a906cb

lib tree : fe8971

simplegit.rb blob : a0a60a


the commit history
branch

}
branch
commit

C1
tree

blob
branching and merging
HEAD

master experiment

C0 C1

C2 C3
C4
master experiment

C3
C0 C5
C1
git checkout -b
experiment
C2
experiment C3

HEAD
T1 master
master experiment

git commit
C0 C4 C1

2 C3 C5
C2 C3

experiment

HEAD
T1 master
master experiment

git commit
C1C0 C1 C4
git commit

C2 C3
C2 C5
C3

experiment

HEAD
HEAD

T1
master git checkout master
master
experiment

C1C0 C1 C4

C2 C3
C2 C5
C3

experiment
git commit
T1 T1
master master

HEAD

C1
C0 C1 C4 C4

C2 C3
C2 C5
C3 C5

experiment experiment
git tag -a ‘v1.1’ T1 T1
master master

HEAD

C1
C0 C1 C4 C4

C2 C3
C2 C5
C3 C5

experiment experiment
T1 master

C0 C1 C4

C2 C3 C5

git checkout experiment experiment

git commit
HEAD
HEAD

T1 master

C0 C1 C4 C6

C2 C3 C5

git checkout master experiment

git merge experiment


remotes
master

C2
origin/master master

C0 C1 C2
master

C2
origin/master master

C0 C1 C2
aster
origin/master master master

C0C1 C1C2 C2
origin/idea

CR2 origin/master

CR1 CR3 CR4

C0 CL1 CL2

git fetch origin


master
origin/idea

CR2 origin/master

CR1 CR3 CR4

C0 CL1 CL2

git fetch origin


master
in/idea origin/idea

CR2 CR2
origin/master origin/master

CR3 CR1
CR4 CR3 CR4

C0
CL2 CL1 CL2 CL3
git checkout -b
tryidea
master master tryidea
origin/idea

CR2 origin/master

CR1 CR3 CR4

C0 CL1 CL2 CL3

master tryidea

git merge origin/master origin/idea


origin/idea

CR2 origin/master

CR1 CR3 CR4

C0 CL1 CL2 CL3

master tryidea
origin/idea

CR2 origin/master

CR1 CR3 CR4

C0 CL1 CL2

master
remote workflow
local repo

public repo public repo

internet

local repo

A B C
local repo

public repo public repo

A B C

internet

git push
(ssh)

local repo

A B C
local repo

git fetch A B C

(git)

public repo public repo

A B C

internet

git push
(ssh)

local repo

A B C
local repo

git fetch A B C

(git) D E F git commit

public repo public repo

A B C

internet

git push
(ssh)

local repo

A B C
local repo

git fetch A B C git push


(git) D E F (ssh)

public repo public repo

A B C A B C

internet D E F

git push
(ssh)

local repo

A B C
local repo

git fetch A B C git push


(git) D E F (ssh)

public repo public repo

A B C A B C

internet D E F

git push git fetch


(ssh) (http)

local repo

A B C

D E F
local repo

git fetch A B C git push


(git) D E F (ssh)

public repo public repo

A B C A B C

internet D E F D E F

git push git fetch


(ssh) (http)

local repo

A B C

D E F
multiple remotes
developer developer
nick jessica

ce0 4a7 5ec master

my repo e4a
developer developer
nick jessica

commit
ce0 4a7 5ec master

my repo e4a
developer developer
nick jessica

tree
ce0 4a7 5ec master

my repo e4a
developer developer
nick jessica

blobs
ce0 4a7 5ec master

my repo e4a
developer developer
nick jessica

ce0 4a7 5ec


schacon/
e4a
project

"public"

git push public


ce0 4a7 5ec master

my repo e4a public/master


ce0 4a7 5ec
developer developer
e4a
nick jessica

git clone (url)

ce0 4a7 5ec


schacon/
e4a
project

"public"

ce0 4a7 5ec master

my repo e4a public/master


ce0 4a7 5ec
developer developer
e4a
nick jessica
24f ec5 c12

git commit

ce0 4a7 5ec


schacon/
e4a
project

"public"

ce0 4a7 5ec master

my repo e4a public/master


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick
24f ec5 c12 git clone (url) jessica

ce0 4a7 5ec


schacon/
e4a
project

"public"

ce0 4a7 5ec master

my repo e4a public/master


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb

git commit a09

ce0 4a7 5ec


schacon/
e4a
project

"public"

ce0 4a7 5ec master

my repo e4a public/master


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb

git push a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"public" a09

ce0 4a7 5ec master

my repo e4a public/master


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"nick" "public" a09

ce0 4a7 5ec master

my repo e4a public/master

git remote add nick


git remote git://github.com/nickh/project.git
add nick git://github.com/nickh/project.git
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb

“nick”
"nick" "public" a09

ce0 4a7 5ec master

my repo e4a public/master

git remote add nick


git remote git://github.com/nickh/project.git
add nick git://github.com/nickh/project.git
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"nick" "public" "jess" a09

ce0 4a7 5ec master

my repo e4a public/master

git remote add add


git remote jessjess
git://github.com/jessica/project.git
git://github.com/jessica/project.git
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"nick" "public" “jess”
"jess" a09

ce0 4a7 5ec master

my repo e4a public/master

git remote add add


git remote jessjess
git://github.com/jessica/project.git
git://github.com/jessica/project.git
5ec ce0 4a7 5ec ce0 4a7 5ec
schacon/ jessica/
e4a e4a
project ce0 4a7 5ec project ce0 4a7 5ec
c12 developer 4ea df7 2fb developer
e4a e4a
"public"
nick "jess" a09 jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec master ce0 4a7 5ec ce0 4a7 5ec
nickh/ schacon/ jessica/
my repo e4a public/master e4a e4a
project project project
24f ec5 c12 nick/master 4ea df7 2fb
"nick" "public" "jess" a09

git fetch nick


ce0 4a7 5ec master

my repo e4a public/master

git fetch nick


git remote add jess git://github.com/jessica/project.git
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"nick" "public" "jess" a09

ce0 4a7 5ec master

my repo e4a public/master

24f ec5 c12 nick/master

git fetch nick


nickh/ schacon/ jessic
e4a e4a
project project proje
24f ec5 c12
ce0 4a7 5ec ce0 4a7 5ec
developer "nick" "public"
developer "jess
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec master

ce0 4a7 5ec ce0 4a7 5ec my repo e4a


ce0 4a7 5ec public/m
nickh/ schacon/ jessica/
e4a e4a 24f
e4a ec5 c12 nick/mas
project project project
24f ec5 c12 4ea df7 2fb jess/mas

"nick" "public" "jess" a09

git fetch jess

ce0 4a7 5ec master


master

my repo e4a public/master


public/master

24f ec5 c12 nick/master

gitgitfetch jess
git remote add jess git://github.com/jessica/project.git
fetch nick
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"nick" "public" "jess" a09

ce0 4a7 5ec master

my repo e4a public/master

24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09

git fetch jess


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 4ea df7 2fb
"nick" "public" "jess" a09

ce0 4a7 5ec


my repo e4a public/master

24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09 c63 b3b master

git merge nick jess


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 24f ec5 c12 4ea df7 2fb
"nick" "public" 4ea df7 2fb "jess" a09
a09 c63 b3b

ce0 4a7 5ec


my repo e4a
24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09 c63 b3b master

public/master

git push public


ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 24f ec5 c12 4ea df7 2fb
"nick" "public" 4ea df7 2fb "jess" a09
a09 c63 b3b

ce0 4a7 5ec


my repo e4a
24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09 c63 b3b master

public/master
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 24f ec5 c12 4ea df7 2fb
"nick" "public" 4ea df7 2fb "jess" a09
a09 c63 b3b

ce0 4a7 5ec


my repo e4a
24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09 c63 b3b master

public/master
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 24f ec5 c12 4ea df7 2fb
"nick" "public" 4ea df7 2fb "jess" a09
a09 c63 b3b

ce0 4a7 5ec


my repo e4a
24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09 c63 b3b master

public/master
ce0 4a7 5ec ce0 4a7 5ec
developer developer
e4a e4a
nick jessica
24f ec5 c12 4ea df7 2fb
a09

ce0 4a7 5ec ce0 4a7 5ec ce0 4a7 5ec


nickh/ schacon/ jessica/
e4a e4a e4a
project project project
24f ec5 c12 24f ec5 c12 4ea df7 2fb
"nick" "public" 4ea df7 2fb "jess" a09
a09 c63 b3b

ce0 4a7 5ec


my repo e4a
24f ec5 c12 nick/master

4ea df7 2fb jess/master

a09 c63 b3b master

public/master
rebasing
local jessica

master C2

C1
local jessica

master C2 C2 master

git clone
C1 C1
local jessica

master C4 C6 master
git commit
C3 C5 git commit
C2 C2

C1 C1
local jessica

master C4 C6 master

pack
git fetch jess
C3 C5

C2 C2

C1 C1
local

master C4 C6 jess/master

C3 C5

C2

C1
git merge

master C4 C6 jess/master

C3 C5

C2

C1
git merge

master C7

C4 C6 jess/master

C3 C5

C2

C1
git merge git rebase

master C7

C4 C6 jess/master master C4 C6 jess/master

C3 C5 C3 C5

C2 C2

C1 C1
git merge git rebase
master C4'

master C7
C3'

C4 C6 jess/master C4 C6 jess/master

C3 C5 C3 C5

C2 C2

C1 C1
git merge git rebase
master C4'

master C7
C3'

C4 C6 jess/master C4 C6 jess/master

C3 C5 C3 C5

C2 C2

C1 C1
git merge git rebase
master C4'

master C7
C3'

C4 C6 jess/master C4 C6 jess/master

C3 C5 C3 C5

C2 C2

C1 C1
git merge git rebase
master C4'
2

master C7 1
C3'

C4 C6 jess/master C4 C6 jess/master

C3 C5 C3 C5

C2 C2

C1 C1
git merge git rebase
master C4'

master C7
C3'

C4 C6 jess/master C4 C6 jess/master

C3 C5 C3 C5

C2 C2

C1 C1
git merge git rebase
master C4'

master C7
C3'

C4 C6 jess/master C6 jess/master

C3 C5 C5

C2 C2

C1 C1
the treeish
the treeish
alternate ways to refer to
objects or ranges of objects
Treeish
• full sha-1 • carrot parent
• partial sha-1 • tilde spec
• branch or tag name • tree pointer
• date spec • blob spec
• ordinal 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
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master^
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master^2
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master~2
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master^^^2
master~2^2
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master^^^2
master~2^2
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master^^^2
master~2^2
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master master
master~3..master^
b3be1 a09c6 df2fa c36ae

5ec47 ce0e4 2f45e 4eadf 2fbb3 18cae

jess/master 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 Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5

ce0 e4a 24f

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


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5

ce0 e4a 24f

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:30 /file2

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:30 /file2

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:30 /file2

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:30 /file2

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:30 /file2

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:30 /file2

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

git checkout
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a e4a 1:30 file2 1:31 /file2

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

vim file2
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a 1ba 1:31 file2 1:31 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a 1ba 1:31 file2 1:31 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a 1ba 1:31 file2 1:31 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f
e4a e4a 1ba 1:31 file2 1:31 /file2

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


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f 1ba
e4a 1ba 1ba 1:31 file2 1:31 /file2

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

git add file2


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f 1ba
e4a 1ba 1ba 1:31 file2 1:31 /file2

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

git add file2


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f 1ba
e4a 1ba 1ba 1:31 file2 1:31 /file2

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

git add file2


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f 1ba
e4a 1ba 1ba 1:31 file2 1:31 /file2

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

git add file2


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f 1ba
e4a 1ba 1ba 1:31 file2 1:31 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12

4a7 ec5 24f 24f 24f 1:30 file1 1:30 /file1


ce0 e4a 24f 1ba
e4a 1ba 1ba 1:31 file2 1:31 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 24f 1:30 file1 1:30 /file1
ce0 e4a 24f 1ba
1ba 1ba 1ba 1:31 file2 1:31 /file2

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

git commit
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 24f 1:30 file1 1:30 /file1
ce0 e4a 24f 1ba
1ba 1ba 1ba 1:31 file2 1:31 /file2

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

git commit
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 24f 1:30 file1 1:30 /file1
ce0 e4a 24f 1ba
1ba 1ba 1ba 1:31 file2 1:31 /file2

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

git commit
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 24f 1:30 file1 1:30 /file1
ce0 e4a 24f 1ba
1ba 1ba 1ba 1:31 file2 1:31 /file2

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

git commit
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

vim file1 file2


git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

vim file1 file2


git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 24f 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

vim file1 file2


git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git add file1


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git add file1


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git add file1


Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d

4a7 ec5 a3e 24f 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git status
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d 6c5

4a7 ec5 a3e 1a7 91b 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git commit
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d 6c5

4a7 ec5 a3e 1a7 91b 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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

git commit
Object Directory Index Working Directory

HEAD git stage wdir mtime fname


master

5ec c12 83d 6c5

4a7 ec5 a3e 1a7 91b 91b 91b 1:32 file1 1:32 /file1
ce0 e4a 24f 1ba 91b
1ba 1ba 6d4 1:32 file2 1:32 /file2

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


How Do I Use Git?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
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


“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:// push
http[s]://
git://
file:///
rsync://
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 list@email.com patches

$ git am mbox
Multiple Commits
1 patch file per commit
in this directory

$ git format-patch -o patches origin


$ git send-email --to list@email.com 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 “production”

develop

topic
master “production”

develop “trunk”

topic
master “production”

develop

convention!
“trunk”

topic
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 C4

C1 C2
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 C4

C1 C2
develop

story95
idea
master

C0

C3 C4

C1 C2
develop

story95
idea
master master

C0 C6

C3 C4 C5

C1 C2
develop idea

story95
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 C4 C5

C1 C2
develop idea

story95
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 C4 C5

C1 C2
develop

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

C0 C6 C7

C3 C4 C5

C1 C2
develop

story95
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 C4 C5

C1 C2
develop

story95

master

C0 C3 C4 C5 C6'

rebase
develop

C1 C2

story95
one more time now!
master

C0

C3 C4

C1 C2
develop

story95
idea
master

C0

C3 C4

C1 C2
develop

story95
idea

git checkout -b idea


master master

C0 C6

C3 C4 C5

C1 C2
develop idea

story95

git commit
master master

C0 C6

C3 C4 C5

C1 C2
develop idea

story95

git checkout master


git commit
master

C0 C6

C3 C4 C5

C1 C2
develop

story95 git checkout idea


git merge develop
git branch -d idea
master

C0 C6 C7

C3 C4 C5

C1 C2
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 • Remotey Commands
• git config • git remote
• git init • git fetch
• git add • git pull
• git commit • git clone
• git status • git push
• git tag
• git log
• Branchy Commands
• git checkout
• git branch
• git merge
• git rebase
• Local Commands • Remotey Commands
• git config • git remote
• git init • git fetch
• git add • git pull
• git commit • git clone
• git status • git push
• git tag • Patchy Commands
• git log • git diff
• Branchy Commands • git apply
• git checkout • git format-patch
• git branch • git am
• git merge
• git rebase
• Local Commands • Remotey Commands
• git config • git remote
• git init • git fetch
• git add • git pull
• git commit • git clone
• git status • git push
• git tag • Patchy Commands
• git log • git diff
• Branchy Commands • git apply
• git checkout • git format-patch
• git branch • git am
• git merge
• git rebase
popular workflows
central repository
model
developer developer

developer developer

shared repository
developer developer

developer developer
shared repository

developer developer developer

git clone
shared repository

developer developer developer

git push
shared repository

developer developer developer

git push
shared repository

developer developer developer


shared repository

developer developer developer

git fetch
git merge
shared repository

developer developer developer

git push
dictator and lieutenants
model
dictator blessed repository

lieutenant

lieutenant

developer developer developer developer


dictator blessed repository

lieutenant

lieutenant

developer developer developer developer

git clone
dictator blessed repository

lieutenant

lieutenant

developer developer developer developer

git fetch
git merge
dictator blessed repository

lieutenant

lieutenant

developer developer developer developer

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

git fetch
integration manager
model
blessed
repository developer developer
public public

integration developer developer


manager private private
github.com
/schacon/ticgit
blessed
/yob/ticgit /pope/ticgit
repository developer developer
public public

integration developer developer


manager private private
github.com
/schacon/ticgit “forks”
blessed
/yob/ticgit /pope/ticgit
repository developer developer
public public

integration developer developer


manager private private
blessed
repository developer developer
public public

integration developer developer


manager private private

git push
blessed
repository developer developer
public public

integration developer developer


manager private private

git clone
blessed
repository developer developer
public public

integration developer developer


manager private private

git push
blessed
repository developer developer
public public

integration developer developer


manager private private

git fetch
git merge
blessed
repository developer developer
public public

integration developer developer


manager private private

git push
blessed
repository developer developer
public public

integration developer developer


manager private private

git fetch
git rebase / merge
blessed
repository developer developer
public public

integration developer developer


manager private private

git push
How Do I Deploy
with Git?
10% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
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% 2m This Slide
4 min
2m Who is Scott?

3m What is Git?

20m How Does Git Work?


75%
35 min

12m How Do I Use Git?

15% 4m How Do I Deploy with Git?


6 min
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
schacon@gmail.com
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 del.icio.us/popular/git peepcode

gitcasts.com #git / #github on IRC schacon@gmail.com

You might also like