0% found this document useful (0 votes)
138 views37 pages

Git Workshop - Trunk Based Development

The document discusses the anatomy of a Git commit, including 40 character revision identifiers that are SHA-1 hashes, tree objects, and commit objects that contain metadata like commit messages and pointers to parent commits. It also covers branches in Git and how features can be developed independently on branches before being merged into the main branch using commands like git branch, git checkout, git add, git commit, and git merge. The document provides examples of creating a new feature branch, adding and committing files to that branch, switching back to the main branch, and then merging the feature branch.

Uploaded by

El'azm Mosleim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views37 pages

Git Workshop - Trunk Based Development

The document discusses the anatomy of a Git commit, including 40 character revision identifiers that are SHA-1 hashes, tree objects, and commit objects that contain metadata like commit messages and pointers to parent commits. It also covers branches in Git and how features can be developed independently on branches before being merged into the main branch using commands like git branch, git checkout, git add, git commit, and git merge. The document provides examples of creating a new feature branch, adding and committing files to that branch, switching back to the main branch, and then merging the feature branch.

Uploaded by

El'azm Mosleim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 37

Git Workshop

Trunk Based Development


https://s.id/6b9ss
Trunk Based
Git
Development
Git
Mental Models
approximations of system behavior

4
Connect to Linux shell
username: git01, git02, …, git11
host: 192.168.1.32
THE ANATOMY OF
A GIT COMMIT
1. 40 character revision
identifiers that are actually
$ echo -n "thoughtram" | openssl sha1
SHA-1 hashes
2. Hashes over hashes
a9eb85ea214a6cfa6882f4be041d5cce7
3. Tree object bee3e45
4. Commit object

6
THE ANATOMY OF
A GIT COMMIT sha1(
meta data
1. 40 character revision
identifiers that are actually commit message
SHA-1 hashes commiter
2. Hashes over hashes
3. Tree object commit date
4. Commit object author
authoring date
Hash-Of-Entire-Working-Directory
)

7
THE ANATOMY OF
A GIT COMMIT
There are four types of objects in Git’s
1. 40 character revision
identifiers that are actually internal storage.
SHA-1 hashes
2. Hashes over hashes
3. Tree object 1) commit objects,
4. Commit object 2) annotated tag objects,
3) blobs, and
4) tree objects

8
THE ANATOMY OF Let’s assume the following project
A GIT COMMIT structure and then examine how it is
represented with the corresponding
1. 40 character revision tree object.
identifiers that are actually
SHA-1 hashes
2. Hashes over hashes .
3. Tree object |-- .git
4. Commit object
|-- assets
| |-- logo.png
| |-- app.css
|-- app.js

9
10
THE ANATOMY OF sha1(
commit message
A GIT COMMIT => "initial commit"

commiter
1. 40 character revision => Christoph Burgdorf <[email protected]>
identifiers that are actually
SHA-1 hashes commit date
=> Sat Nov 8 10:56:57 2014 +0100
2. Hashes over hashes
3. Tree object Author
4. Commit object => Christoph Burgdorf <[email protected]>

author date
=> Sat Nov 8 10:56:57 2014 +0100

Tree
=> 9c435a86e664be00db0d973e981425e4a3ef3f8d
)

11
Source: A Tale of Three Trees (by Scott Chacon)
12
sha1(
commit message
THE ANATOMY OF => "initial commit"

A GIT COMMIT commiter


=> Christoph Burgdorf <[email protected]>
1. 40 character revision commit date
identifiers that are actually => Sat Nov 8 10:56:57 2014 +0100
SHA-1 hashes
2. Hashes over hashes Author
3. Tree object => Christoph Burgdorf <[email protected]>
4. Commit object
author date
=> Sat Nov 8 10:56:57 2014 +0100

Tree
=> 9c435a86e664be00db0d973e981425e4a3ef3f8d

Parents
=> [0d973e9c4353ef3f8ddb98a86e664be001425e4a]
) 13
Source: A Tale of Three Trees (by Scott Chacon)
14
Git = Blockchain
Mind = Blown
https://medium.com/@shemnon/is-a-git-repository-a-block
chain-35cb1cd2c491

15
16
UNDERSTANDING
BRANCHES IN GIT
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

17
UNDERSTANDING
BRANCHES IN GIT $ git branch feature
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

18
UNDERSTANDING
BRANCHES IN GIT
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

19
UNDERSTANDING
BRANCHES IN GIT $ git checkout feature
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

20
$ vim file.txt
UNDERSTANDING $ git add file.txt
BRANCHES IN GIT $ git commit -m “yay, that’s fun”
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

21
$ git checkout master
UNDERSTANDING
BRANCHES IN GIT
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

22
$ vim anotherFile.txt
UNDERSTANDING $ git add anotherFile.txt
BRANCHES IN GIT $ git commit -m "yay, more fun!"
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

23
UNDERSTANDING
BRANCHES IN GIT $ git merge --no-ff feature
1. Simple commit history
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch

24
sha1(
commit message
UNDERSTANDING => "Merge branch ‘feature’"

BRANCHES IN GIT commiter


=> Christoph Burgdorf <[email protected]>
1. Simple commit history commit date
2. New “feature” branch => Sat Nov 8 12:56:57 2014 +0100
3. HEAD pointer
4. Checkout “feature” branch Author
5. Add new file => Christoph Burgdorf <[email protected]>
6. Checkout “master” branch
7. Add another file author date
=> Sat Nov 8 12:56:57 2014 +0100
8. Merge “feature” branch
Tree
=> 66ga62314ab62d393f6b055c0aef1c7299a25a5a25f6e

Parents
=> [3aa2ff, c57e22]
) 25
What if we model it as
if it was a relational
database?
Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 2 null

2 master null a5c3eb

27
Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 2 null

2 master null a5c3eb

3 feature null a5c3eb 28


Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 2 null

2 master null a5c3eb

3 feature null a5c3eb 29


Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer
4. Checkout “feature” branch
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 3 null

2 master null a5c3eb

3 feature null a5c3eb 30


Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null

4. Checkout “feature” branch


5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 3 null

2 master null a5c3eb

3 feature null c57e22 31


Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null

4. Checkout “feature” branch


5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 2 null

2 master null a5c3eb

3 feature null c57e22 32


Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null

4. Checkout “feature” branch 3aa2ff 1jh351ha13 Sat Nov 8 Christoph fifth a5c3eb null
5. Add new file
6. Checkout “master” branch
7. Add another file
8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 2 null

2 master null 3aa2ff

3 feature null c57e22 33


Commit
UNDERSTANDING id what when who why parent1 parent2

BRANCHES IN GIT 339aa3 9c435a86e6 Sat Nov 8 Christoph initial null null

92f94a 6d345686e6 Sat Nov 8 Christoph second 339aa3 null

1. Simple commit history a5c3eb 1g62h6786e Sat Nov 8 Christoph third 92f94a null
2. New “feature” branch
3. HEAD pointer c57e22 6a16j1736j Sat Nov 8 Christoph fourth a5c3eb null

4. Checkout “feature” branch 3aa2ff 1jh351ha13 Sat Nov 8 Christoph fifth a5c3eb null
5. Add new file
6. Checkout “master” branch a35e4v 66ga62314a Sat Nov 8 Christoph Merge feature 3aa2ff c57e22

7. Add another file


8. Merge “feature” branch
Pointer
id label pointer_id commit_id

1 HEAD 2 null

2 master null a35e4v

3 feature null c57e22 34


Trunk Based Development
1. https://blog.thoughtram.io/git/2014/11/18/th
e-anatomy-of-a-git-commit.html

2. https://blog.thoughtram.io/git/rebase-book/20

References
15/02/10/understanding-branches-in-git.html

3. https://github.com/thoughtram/rebase-book/
blob/master/manuscript/branching-in-git.md

4. https://speakerdeck.com/schacon/a-tale-of-th
ree-trees

5. https://speakerdeck.com/jirichara/trunk-base
d-development

6. https://trunkbaseddevelopment.com

7. https://unsplash.com/photos/ywRNdDfvMWs
Thanks!
Leonardo Situmorang
[email protected]
@ldoreno

You might also like