+ All Categories
Home > Documents > git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65....

git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65....

Date post: 21-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
239
Git from the inside out
Transcript
Page 1: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git from the inside out

Page 2: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Talk structure

Page 3: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git is a graph

Page 4: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git is a graph

This graph dictates Git’s behaviour

Page 5: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git is a graph

If you understand this graph, you understand Git

Page 6: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Run Git commands on a repository

Page 7: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Observe how those commands change the graph

Page 8: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a project

Page 9: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a project ~ $ mkdir alpha

Page 10: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a project ~ $ mkdir alpha ~ $ cd alpha ~/alpha $

Page 11: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create data directory

~/alpha $ mkdir data

Page 12: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create data/letter.txt

~/alpha $ mkdir data ~/alpha $ printf 'a' > data/letter.txt

Page 13: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Project layout

~/alpha $ tree alpha !"" data !"" letter.txt

Page 14: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Initialize the repository

Page 15: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Initialize the repository ~/alpha $ git init Initialized repository

Page 16: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

File layout ~/alpha $ git init Initialized repository ~/alpha $ tree -a alpha !"" data !"" letter.txt

Page 17: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

File layout ~/alpha $ git init Initialized repository ~/alpha $ tree -a alpha #"" data | !"" letter.txt !"" .git !"" objects etc...

Page 18: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Add a new file to Git

Page 19: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Add data/letter.txt to Git

~/alpha $ git add data/letter.txt

Page 20: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Create a blob object ~/alpha $ git add data/letter.txt ~/alpha $ tree -a .git .git !"" objects !"" 2e !"" 65

Page 21: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Hashes

Page 22: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Hash of data/letter.txt content

~/alpha $ git hash-object data/letter.txt 2e65

Page 23: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Create a blob object ~/alpha $ git add data/letter.txt ~/alpha $ tree -a .git .git !"" objects !"" 2e !"" 65

~/alpha $ git hash-object data/letter.txt 2e65

Page 24: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Create a blob object ~/alpha $ git add data/letter.txt ~/alpha $ tree -a .git .git !"" objects !"" 2e !"" 65 ~/alpha $ cat .git/objects/2e/65 xK??OR0dH

Page 25: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Create a blob object ~/alpha $ git add data/letter.txt ~/alpha $ tree -a .git .git !"" objects !"" 2e !"" 65 ~/alpha $ cat .git/objects/2e/65 xK??OR0dH ~/alpha $ git cat-file -p 2e65 a

Page 26: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make an entry in the index ~/alpha $ git add data/letter.txt - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/index ?H?u.data/letter.txtd

Page 27: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make an entry in the index ~/alpha $ git add data/letter.txt - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/index ?H?u.data/letter.txtd ~/alpha $ git ls-files -s data/letter.txt 2e65

Page 28: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make an entry in the index ~/alpha $ git add data/letter.txt - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/index ?H?u.data/letter.txtd ~/alpha $ git ls-files -s data/letter.txt 2e65

Page 29: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Re-add a file to a repository

Page 30: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After data/letter.txt added

a

index

a workingcopy

data/letter.txtdata/letter.txt

Page 31: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create data/number.txt

~/alpha $ printf '1234' > data/number.txt

Page 32: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create data/number.txt

~/alpha $ printf '1234' > data/number.txt

a

index

1234

a workingcopy

data/letter.txtdata/letter.txt

data/number.txt

Page 33: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Add data/number.txt

~/alpha $ git add data/number.txt

a

index

1234

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt 1234

Page 34: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Edit data/number.txt

~/alpha $ printf '1' > data/number.txt

a

index

1

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt 1234

Page 35: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Add data/number.txt

~/alpha $ printf '1' > data/number.txt ~/alpha $ git add data/number.txt

a

index

1

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt 1

1234

Page 36: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make a commit

Page 37: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make a commit ~/alpha $ git commit -m 'a1' master 774b

Page 38: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Before the commit

a 1

Page 39: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

Page 40: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

Page 41: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

Page 42: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

Page 43: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

Page 44: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

Page 45: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 0eed blob 2e65 letter.txt blob 56a6 number.txt

a 1

data

Page 46: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p ffe2 tree 0eed data

a 1

data

Page 47: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p ffe2 tree 0eed data

a 1

data

Page 48: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p ffe2 tree 0eed data

a 1

data

Page 49: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p ffe2 tree 0eed data

a 1

root

data

Page 50: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make the commit object ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 774b tree ffe2 author [email protected] 1424798436 a1

a 1

root

data

Page 51: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make the commit object ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 774b tree ffe2 author [email protected] 1424798436 a1

a 1

root

data

Page 52: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make the commit object ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 774b tree ffe2 author [email protected] 1424798436 a1

a 1

root

data

Page 53: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make the commit object ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 774b tree ffe2 author [email protected] 1424798436 a1

a 1

root

data

Page 54: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make the commit object ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 774b tree ffe2 author [email protected] 1424798436 a1

a 1

root

data

Page 55: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Make the commit object ~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ git cat-file -p 774b tree ffe2 author [email protected] 1424798436 a1

a1

a 1

root

data

Page 56: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the new commit

~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/HEAD ref: refs/heads/master

a1

a 1

root

data

Page 57: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the new commit

~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/HEAD ref: refs/heads/master ~/alpha $ cat .git/refs/heads/master 774b

a1

a 1

root

data

Page 58: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the new commit

~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/HEAD ref: refs/heads/master ~/alpha $ cat .git/refs/heads/master 774b

~/alpha $ git commit -m 'a1' master 774b

a1

a 1

root

data

Page 59: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the new commit

~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/HEAD ref: refs/heads/master ~/alpha $ cat .git/refs/heads/master 774b

a1

a 1

root

data

master

Page 60: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the new commit

~/alpha $ git commit -m 'a1' - - - - - - - - - - - - - - - - - - - - - - - - - - ~/alpha $ cat .git/HEAD ref: refs/heads/master ~/alpha $ cat .git/refs/heads/master 774b

a1

a 1

root

data

HEAD

master

Page 61: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make a commit that is not the first commit

Page 62: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After the first commit

a

1

root

data

a1

index1

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

Page 63: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Edit number.txt

~/alpha $ printf '2' > data/number.txt

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

Page 64: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Add number.txt

~/alpha $ git add data/number.txt

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

2

Page 65: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make a2 commit

~/alpha $ git commit -m 'a2' master f0af

Page 66: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Make a tree graph of the contents of the index ~/alpha $ git commit -m 'a2' master f0af

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

2

root

data

Page 67: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Create the commit object ~/alpha $ git commit -m 'a2' master f0af ~/alpha $ git cat-file -p f0af tree ce72 parent 774b author [email protected] 1424798436 a2

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

2

root

data

a2

Page 68: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the new commit

~/alpha $ git commit -m 'a2' master f0af

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

2

root

data

a2

Page 69: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Content is stored as trees

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 70: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Content is stored as trees

The objects database stores diffs

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 71: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Each commit has a parent

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 72: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Each commit has a parent

A repository stores the history of a project

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 73: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Refs are entry points to the commit history

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 74: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Refs are entry points to the commit history

Commits can be given meaningful names

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 75: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Objects are immutable

Page 76: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Objects are immutable

Content is edited, not deleted

Page 77: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Refs are mutable

Page 78: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Refs are mutable

The meaning of a ref can change

Page 79: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out a commit

Page 80: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out a commit ~/alpha $ git checkout f0af HEAD is detached

Page 81: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out a commit ~/alpha $ git checkout f0af HEAD is detached

Page 82: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out a commit ~/alpha $ git checkout f0af HEAD is detached

~/alpha $ git commit -m 'a2' master f0af

Page 83: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Write the commit tree to the working copy ~/alpha $ git checkout f0af HEAD is detached

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

2

root

data

a2

Page 84: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Write the commit tree to the index ~/alpha $ git checkout f0af HEAD is detached

a

1

root

data

a1

index2

a workingcopy

data/letter.txt

data/number.txt

data/letter.txt

data/number.txt

HEAD

master

2

root

data

a2

Page 85: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the thing that was checked out

~/alpha $ git checkout f0af HEAD is detached ~/alpha $ cat .git/HEAD f0af

Page 86: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the thing that was checked out

~/alpha $ git checkout f0af HEAD is detached ~/alpha $ cat .git/HEAD f0af

~/alpha $ cat .git/HEAD ref: refs/heads/master

Page 87: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point HEAD at the thing that was checked out

~/alpha $ git checkout f0af HEAD is detached ~/alpha $ cat .git/HEAD f0af

a

1

root

data

a1

HEAD

master

2

root

data

a2

Page 88: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit a3

~/alpha $ printf '3' > data/number.txt

Page 89: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit a3

~/alpha $ printf '3' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a3' detached HEAD 3645

Page 90: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit a3

~/alpha $ printf '3' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a3' detached HEAD 3645

Page 91: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit a3

~/alpha $ printf '3' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a3' detached HEAD 3645

a

1

root

data

a1

HEAD

master

2

root

data

a2

3

root

data

a3

Page 92: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a branch

Page 93: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a branch ~/alpha $ git branch deputy

Page 94: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a branch ~/alpha $ git branch deputy ~/alpha $ cat .git/refs/heads/deputy 3645

Page 95: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Create a branch ~/alpha $ git branch deputy ~/alpha $ cat .git/refs/heads/deputy 3645

a

1

root

data

a1

HEAD

master

2

root

data

a2

3

root

data

a3

deputy

Page 96: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Branches are just refs, refs are just files

Page 97: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Branches are just refs, refs are just files

Branches are lightweight

Page 98: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out a branch

Page 99: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

~/alpha $ git checkout master Switched to branch master

Check out master

Page 100: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

~/alpha $ git checkout master Switched to branch master

1. Write the commit tree to the working copy

a

1

root

data

a1

HEAD

master

2

root

data

a2

3

root

data

a3

deputy

workingcopy index

2

a

Page 101: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

~/alpha $ git checkout master Switched to branch master

2. Write the commit tree to the index

a

1

root

data

a1

HEAD

master

2

root

data

a2

3

root

data

a3

deputy

workingcopy index

2

a

Page 102: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

~/alpha $ git checkout master Switched to branch master

3. Point HEAD at the thing that was checked out

a

1

root

data

a1

HEAD

master

2

root

data

a2

3

root

data

a3

deputy

workingcopy index

2

a

Page 103: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge an ancestor

Page 104: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out deputy

~/alpha $ git checkout deputy Switched to branch deputy

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 105: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge master (a2) into deputy (a3)

~/alpha $ git merge master Already up-to-date

Page 106: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

A commit is a set of changes

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 107: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

A commit is a set of changes

If an ancestor is merged into a descendent, Git does nothing

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 108: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge a descendent

Page 109: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out master

~/alpha $ git checkout master Switched to branch master

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 110: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge deputy (a3) into master (a2)

~/alpha $ git merge deputy Fast-forward

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 111: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

A commit is a set of changes

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 112: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

A commit is a set of changes

If a descendent is merged into an ancestor, history is not changed but

HEAD is changed

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

etc

Page 113: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit a4 on master

~/alpha $ printf '4' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a4' master 7b7b

Page 114: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit a4 on master

~/alpha $ printf '4' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'a4' master 7b7b

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

Page 115: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out deputy

~/alpha $ git checkout deputy Switched to branch deputy

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

Page 116: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit b3 to deputy

~/alpha $ printf 'b' > data/letter.txt ~/alpha $ git add data/letter.txt ~/alpha $ git commit -m 'b3' deputy 982d

Page 117: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit b3 to deputy

~/alpha $ printf 'b' > data/letter.txt ~/alpha $ git add data/letter.txt ~/alpha $ git commit -m 'b3' deputy 982d

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 118: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commits can share parents

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 119: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commits can share parents

New lineages can be created

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 120: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge two commits from different lineages

Page 121: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commits can have multiple parents

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

Page 122: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commits can have multiple parents

Lineages can be joined with a merge commit

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

Page 123: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge master (a4) into deputy (b3)

~/alpha $ git merge master -m 'b4' Merged

Page 124: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge master (a4) into deputy (b3)

~/alpha $ git merge master -m 'b4' Merged

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

Page 125: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commits have parents

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 126: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commits have parents

It is possible to find the point at which two lineages diverged

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 127: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

a3a4

b3

base giverreceiver

Page 128: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

a3

a4

b3

a a

base giverreceiver

letter.txt b

Page 129: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

A merge has a base commit

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 130: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

A merge has a base commit

Git can automatically resolve the merge of a file that has changed from the base in

only the receiver or giver

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3

Page 131: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changesmade by the receiver and giver

a3

a4

b3

a a

base giverreceiver diff

letter.txt b b

Page 132: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

a3

a4

b3

a

4

a

base giverreceiver diff

letter.txt

number.txt

b

3 3

b

Page 133: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

a3

a4

b3

a

4

a

base giverreceiver diff

4

letter.txt

number.txt

b

3 3

b

Page 134: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Apply the diff to the working copy

a3

a4

b3

a

4

a

base giverreceiver diff working copy

4

letter.txt

number.txt

b

3 3

b

4

b

Page 135: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Apply the diff to the index

a3

a4

b3

a

4

a

base giverreceiver diff working copy index

4

letter.txt

number.txt

b

3 3

b

4

b

4

b

Page 136: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

4. Commit the updated index ~/alpha $ git cat-file -p a2ec tree 2029 parent 982d parent 7b7b author [email protected] 1424798436 b4

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

Page 137: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

5. Point HEAD at the new commit ~/alpha $ cat .git/refs/heads/deputy a2ec

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

Page 138: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge commits from different lineages, where the commits both

modify the same file

Page 139: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Check out master

~/alpha $ git checkout master Switched to branch master

Page 140: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge deputy into master to bring master up to date

~/alpha $ git checkout master Switched to branch master ~/alpha $ git merge deputy Fast-forward

Page 141: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge deputy into master to bring master up to date

~/alpha $ git checkout master Switched to branch master ~/alpha $ git merge deputy Fast-forward

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

Page 142: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit b5 to deputy

~/alpha $ git checkout deputy Switched to branch deputy ~/alpha $ printf '5' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'b5' deputy bd79

Page 143: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Make commit b6 to master

~/alpha $ git checkout master Switched to branch master ~/alpha $ printf '6' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m 'b6' master 4c3c

Page 144: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After making commits b5 and b6

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

b6

b5

Page 145: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge deputy (b5) into master (b6)

~/alpha $ git merge deputy Conflict in data/number.txt

Page 146: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

b4b5

b6

base giverreceiver

Page 147: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

b4

b5

b6

b b

base giverreceiver

bletter.txt

Page 148: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

b4

b5

b6

b b

base giverreceiver diff

bletter.txt

Page 149: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

b4

b5

b6

4

b

5

b

6

base giverreceiver diff

bletter.txt

number.txt

Page 150: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Generate the diff that combines the changes made by the receiver and giver

b4

b5

b6

4

b

5

b

6

base giverreceiver diff

b

56

letter.txt

number.txt

Page 151: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Apply the diff to the working copy

b4

b5

b6

4

b

5

b

6

base giverreceiver diff working copy

b

56 ...

letter.txt

number.txt

Page 152: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The number.txt conflict in the working copy

<<<<<<< HEAD 6 ======= 5 >>>>>>> deputy

Page 153: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Apply the diff to the index

b4

b5

b6

4

b

5

b

6

base giverreceiver diff working copy index

b

56 ... ...

letter.txt

number.txt

Page 154: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index before the merge

0 data/letter.txt 63d8 0 data/number.txt 62f9

Page 155: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index before the merge

0 data/letter.txt 63d8 0 data/number.txt 62f9

Page 156: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index after the merge

0 data/letter.txt 63d8 1 data/number.txt bf0d 2 data/number.txt 62f9 3 data/number.txt 7813

Page 157: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index after the merge

0 data/letter.txt 63d8 1 data/number.txt bf0d 2 data/number.txt 62f9 3 data/number.txt 7813

Page 158: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index after the merge

0 data/letter.txt 63d8 1 data/number.txt bf0d 2 data/number.txt 62f9 3 data/number.txt 7813

Page 159: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index after the merge

0 data/letter.txt 63d8 1 data/number.txt bf0d 2 data/number.txt 62f9 3 data/number.txt 7813

Page 160: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

4. The user resolves the conflicts in the working copy

~/alpha $ printf '11' > data/number.txt

Page 161: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

4. The user resolves the conflicts in the index

~/alpha $ printf '11' > data/number.txt ~/alpha $ git add data/number.txt

Page 162: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The index after the conflict in number.txt was resolved

0 data/letter.txt 63d8 0 data/number.txt 9d60

Page 163: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

6. The user commits the merge ~/alpha $ git commit -m 'b11' master 251a

Page 164: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

6. The user commits the merge ~/alpha $ git commit -m 'b11' master 251a

a 1

root

data

a1

HEAD

master

2

root

data

a2 a3

deputy

a4

b3b4

b6

b5b11

Page 165: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Remove a file

Page 166: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After the b11 commit

a1

HEAD

master

a2 a3

deputy

a4

b3b4

b6

b5b11

b

11

root

data

working copy index11

b

Page 167: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Remove letter.txt

~/alpha $ git rm data/letter.txt Removed data/letter.txt

Page 168: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Remove letter.txt

~/alpha $ git rm data/letter.txt Removed data/letter.txt

a1

HEAD

master

a2 a3

deputy

a4

b3b4

b6

b5b11

b

11

root

data

working copy index11

Page 169: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commit the removal of letter.txt

~/alpha $ git commit -m '11' master d14c

Page 170: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Commit the removal of data/letter.txt

~/alpha $ git commit -m '11' master d14c

a1

HEAD

master

a2 a3

deputy

a4

b3b4

b6

b5b11

b

11

root

data

working copyindex11

11

root

data

Page 171: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Copy a repository

Page 172: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Copy the alpha repository to the bravo directory

~/alpha $ cd .. ~ $ cp -R alpha bravo

Page 173: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Copy the alpha repository to the bravo directory

~/alpha $ cd .. ~ $ cp -R alpha bravo ~ $ tree -a ~ #"" alpha | #"" data | | !"" number.txt | !"" .git | etc... !"" bravo #"" data | !"" number.txt !"" .git etc...

Page 174: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Copy the alpha repository to the bravo directory

~/alpha $ cd .. ~ $ cp -R alpha bravo ~ $ tree -a ~ #"" alpha | #"" data | | !"" number.txt | !"" .git | etc... !"" bravo #"" data | !"" number.txt !"" .git etc...

Page 175: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Copy the alpha repository to the bravo directory

~/alpha $ cd .. ~ $ cp -R alpha bravo ~ $ tree -a ~ #"" alpha | #"" data | | !"" number.txt | !"" .git | etc... !"" bravo #"" data | !"" number.txt !"" .git etc...

Page 176: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Copy the alpha repository to the bravo directory

~/alpha $ cd .. ~ $ cp -R alpha bravo ~ $ tree -a ~ #"" alpha | #"" data | | !"" number.txt | !"" .git | etc... !"" bravo #"" data | !"" number.txt !"" .git etc...

Page 177: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The alpha and bravo repositories

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

Page 178: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Connect a repository to another repository

Page 179: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Move to the alpha repository

~ $ cd alpha ~/alpha $

Page 180: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set bravo as a remote repository on alpha

~ $ cd alpha ~/alpha $ git remote add bravo ../bravo

Page 181: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set bravo as a remote repository on alpha

~ $ cd alpha ~/alpha $ git remote add bravo ../bravo

Page 182: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set bravo as a remote repository on alpha

~ $ cd alpha ~/alpha $ git remote add bravo ../bravo

Page 183: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set bravo as a remote repository on alpha

~ $ cd alpha ~/alpha $ git remote add bravo ../bravo ~/alpha $ cat .git/config remote bravo url = ../bravo

Page 184: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Fetch a branch from a remote repository

Page 185: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Move to the bravo repository

~/alpha $ cd ../bravo ~/bravo $

Page 186: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set number.txt to '12' and commit

~/alpha $ cd ../bravo ~/bravo $ printf '12' > data/number.txt ~/bravo $ git add data/number.txt ~/bravo $ git commit -m '12' master 94cd

Page 187: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After the 12 commit made to bravo

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

Page 188: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Move to the alpha repository

~/bravo $ cd ../alpha ~/alpha $

Page 189: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Fetch master from bravo into alpha

~/bravo $ cd ../alpha ~/alpha $ git fetch bravo master Fetching objects master -> FETCH_HEAD

Page 190: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Find the HEAD commit on the repository being fetched

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

Page 191: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Copy to the fetching repository the HEAD commit and its dependent objects

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

12

root

data

Page 192: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point the ref for the remote branch at the fetched commit

~/alpha $ cat .git/refs/remotes/bravo/master 94cd

Page 193: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point the ref for the remote branch at the fetched commit

~/alpha $ cat .git/refs/remotes/bravo/master 94cd

Page 194: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point the ref for the remote branch at the fetched commit

~/alpha $ cat .git/refs/remotes/bravo/master 94cd

Page 195: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point the ref for the remote branch at the fetched commit

~/alpha $ cat .git/refs/remotes/bravo/master 94cd

Page 196: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point the ref for the remote branch at the fetched commit

~/alpha $ cat .git/refs/remotes/bravo/master 94cd

Page 197: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Point the ref for the remote branch at the fetched commit

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

12

root

data

bravo/master

Page 198: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

4. Point FETCH_HEAD at the fetched commit

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

12

root

data

bravo/master

FETCH_HEAD

Page 199: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

~/alpha $ cat .git/FETCH_HEAD master on bravo 94cd

4. Point FETCH_HEAD at the fetched commit

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

12

root

data

bravo/master

FETCH_HEAD

Page 200: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Objects can be copied

Page 201: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Objects can be copied

History can be shared between repositories

Page 202: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Repositories store remote refs

Page 203: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Repositories store remote refs

A repository can record locally the state of a branch on a remote repository

Page 204: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge FETCH_HEAD

Page 205: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Merge FETCH_HEAD

~/alpha $ git merge FETCH_HEAD Fast-forward

Page 206: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Before merging FETCH_HEAD

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

12

root

data

bravo/master

FETCH_HEAD

Page 207: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After merging FETCH_HEAD

~/alpha $ git merge FETCH_HEAD Fast-forward

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphabravo

12

data

12

root

data

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

12

root

data

bravo/master

FETCH_HEAD

Page 208: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Pull a branch from a remote

Page 209: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Pull master from bravo into alpha

~/alpha $ git pull bravo master Already up-to-date

Page 210: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Clone a repository

Page 211: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Clone alpha to charlie

~/alpha $ cd .. ~ $ git clone alpha charlie Cloned into charlie

Page 212: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Create the directory for the new repository ~/alpha $ cd .. ~ $ git clone alpha charlie Cloned into charlie ~ $ ls alpha bravo charlie

Page 213: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Move into the clone’s directory ~/alpha $ cd .. ~ $ git clone alpha charlie Cloned into charlie ~ $ ls alpha bravo charlie ~ $ cd charlie ~/charlie $

Page 214: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

3. Initialize the clone’s directory as a Git repository ~/alpha $ cd .. ~ $ git clone alpha charlie Cloned into charlie ~ $ ls alpha bravo charlie ~ $ cd charlie ~/charlie $ tree .git !"" objects etc...

Page 215: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

4. Check out the branch that was checked out on the repository being cloned

~/alpha $ cd .. ~ $ git clone alpha charlie Cloned into charlie - - - - - - - - - - - - - - - - - - - - - - - - - - ~/charlie $ cat .git/HEAD ref: refs/heads/master

Page 216: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

5. Pull the branch that was checked out on the repository being cloned

~/alpha $ cd .. ~ $ git clone alpha charlie Cloned into charlie - - - - - - - - - - - - - - - - - - - - - - - - - - ~/charlie $ cat .git/HEAD ref: refs/heads/master ~/charlie $ cat .git/refs/heads/master 94cd

Page 217: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Move into alpha

~/charlie $ cd ../alpha ~/alpha $

Page 218: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set number.txt to '13' and commit to master

~/charlie $ cd ../alpha ~/alpha $ printf '13' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m '13' master 3238

Page 219: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set charlie as a remoterepository on alpha

~/charlie $ cd ../alpha ~/alpha $ printf '13' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m '13' master 3238 ~/alpha $ git remote add charlie ../charlie

Page 220: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Push master to charlie

~/charlie $ cd ../alpha ~/alpha $ printf '13' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m '13' master 3238 ~/alpha $ git remote add charlie ../charlie ~/alpha $ git push charlie master Writing objects. Refusing to update the checked out branch because it will make the index and working copy inconsistent

Page 221: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Before the push

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphacharlie

12a4

a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

13

root

data

13

Page 222: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After the push

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphacharlie

12a4

a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12

data

13

root

data

13

data

13

root

data

13

Page 223: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Push master to charlie

~/charlie $ cd ../alpha ~/alpha $ printf '13' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m '13' master 3238 ~/alpha $ git remote add charlie ../charlie ~/alpha $ git push charlie master Writing objects. Refusing to update the checked out branch because it will make the index and working copy inconsistent

Page 224: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Push master to charlie

~/charlie $ cd ../alpha ~/alpha $ printf '13' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m '13' master 3238 ~/alpha $ git remote add charlie ../charlie ~/alpha $ git push charlie master Writing objects. Refusing to update the checked out branch because it will make the index and working copy inconsistent

Page 225: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Clone a bare repository

Page 226: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Clone alpha to bare repository delta

~/alpha $ cd .. ~ $ git clone alpha delta --bare Cloning into bare repository delta

Page 227: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

File layout of delta

~/alpha $ cd .. ~ $ git clone alpha delta --bare Cloning into bare repository delta ~ $ tree delta delta #"" config !"" objects etc...

Page 228: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

The alpha and delta repositories

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphadelta

12a4

a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12 13

13

Page 229: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Move into alpha

~ $ cd alpha ~/alpha $

Page 230: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set delta as a remote repository on alpha

~ $ cd alpha ~/alpha $ git remote add delta ../delta

Page 231: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Set number.txt to '14' and commit

~ $ cd alpha ~/alpha $ git remote add delta ../delta ~/alpha $ printf '14' > data/number.txt ~/alpha $ git add data/number.txt ~/alpha $ git commit -m '14' master cb51

Page 232: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

After the 14 commit made to alpha

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphadelta

12a4

a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12 13

13

data

14

root

data

14

Page 233: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Push master to delta

~/alpha $ git push delta master Writing objects To ../delta 3238..cb51 master

Page 234: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

1. Copy the commit at HEAD and its dependent objects to the remote repository

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphadelta

12a4

a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12 13

13

data

14

root

data

14

data

14

root

data

14

Page 235: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

2. Point HEAD on the remote to the pushed HEAD commit

a4a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

alphadelta

12a4

a1 a3a2

HEAD

masterdeputy

b3b4

b6

b5b11 11

12 13

13

data

14

root

data

14

data

14

root

data

14

Page 236: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Phew

Page 237: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git is a graph

Page 238: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git is a graph

This graph dictates Git’s behaviour

Page 239: git from the inside out 2 - maryrosecook.com · ~/alpha $ git ls-files -s data/letter.txt 2e65. Re-add a file to a repository. After data/letter.txt added a index a working ...

Git is a graph

If you understand this graph, you understand Git


Recommended