Git: Contrôle des versions,
gestion des sources et bien plus encore...

Session 1 - That’s (g)it !
Sébastien DAWANS
26/11/...
About me…

Internet
of Things

Internet

6LBR
WSN

http://cetic.github.io/6lbr
www.cetic.be/6lbr (FR!)

http://cetic.githu...
About me…

Internet
of Things

Internet

6LBR

Powered by Git !
WSN

http://cetic.github.io/6lbr
www.cetic.be/6lbr (FR!)

...
S C M
«S C
ource

ode

oftware

anagement

onfiguration

M

anagement

»
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

»
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

»
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

« branch »

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

« branch »

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

« branch »

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

« branch »

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

« branch »

»

Durée?
S C M
«S C
ource

ode

oftware

&

anagement

onfiguration

M

anagement

« branch »

»

Durée?

« merge »
Panorama des SCM
Un peu
d’histoire…
2002

1991
Manual tarballs,
patches, mails

« Much superior source
control management
system than CVS i...
Un peu
d’histoire…
2002

1991
Manual tarballs,
patches, mails

« Much superior source
control management
system than CVS i...
Un peu
d’histoire…
2002

1991
Manual tarballs,
patches, mails

« Much superior source
control management
system than CVS i...
not an evolution
rcs

cvs

svn

git
not an evolution
rcs

cvs

svn

git
Git is…

Distributed
Fast
Reliable
Centralized SCM
Central
CVS/SVN
Dan
‘The Boss’

Alice
Bob

Charlie
Centralized SCM
Central
CVS/SVN

Single Point
of Failure

Dan
‘The Boss’

Alice
Bob

Charlie
Centralized SCM
Central
CVS/SVN

Network
(slow)

Single Point
of Failure

Dan
‘The Boss’

Alice
Bob

Charlie
Centralized SCM
Central
CVS/SVN

Network
(slow)

Single Point
of Failure

Dan
‘The Boss’

Alice
Bob

Charlie

Access
Right...
Git is Distributed

Dan
The Boss

Charlie

Alice

Bob
Git is Distributed
No a priori structure
Dan
The Boss

Charlie

Alice

Bob
Git is Distributed
No a priori structure
Dan
The Boss

Charlie

Alice

Bob

But Git ≠ Anarchy
Git is Distributed
A very common practice:
Sharing via user-owned repos
Dan
Public

Dan
The Boss

Charlie

Charlie
Public
...
Git is Distributed
A very common practice:
Sharing via user-owned repos
RD/WR
Dan
Public

Dan
The Boss

Charlie

Charlie
P...
Git is Distributed
A very common practice:
Sharing via user-owned repos
Dan
Public

Charlie
Public

Where to host these?
A...
Git is Distributed
Shared Repositories

Dan
Public

Charlie
Public
Alice
Public
Bob
Public

« In-House », entreprise-local...
Git is Distributed
Shared Repositories

Dan
Public

Charlie
Public
Alice
Public
Bob
Public

« In-House », entreprise-local...
Distributed Workflow Example

Integration-Manager
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo

Alice

Bob

Dan
The Boss
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo

Only Dan
may WRITE

Alice

Bob

Dan
The Boss
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo

Other developers
only READ

Alice

Bob

Dan
The B...
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo
Alice
Public

Bob
Public

develop, commit

Alice

...
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo
Alice
Public

Bob
Public

Share
Features
Alice

Bo...
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo
Alice
Public

Bob
Public

Alice

Bob

Integrate
Fe...
Distributed Workflow Example
« Integration-Manager » (Dan)
Blessed
Repo
Alice
Public

Bob
Public

New
Release

Alice

Bob
...
Distributed Workflow Example

Integration-Manager
Dictator & Lieutenants
Dictator & Lieutenants Workflow
« Network of Trust » (Linux)

Dictator

torvalds/linux
Blessed
Repository

Lieutenants

Pl...
Git is…

Distributed
Fast
Reliable
Git is Fast
1. Because it’s distributed: No network
overhead for daily operations:
– Commit changes
– Compare revisions
– ...
Git is Fast
1. Because it’s distributed: No network
overhead for daily operations:
– Commit changes
– Compare revisions
– ...
Git is Fast
1. Because it’s distributed: No network
overhead for daily operations:
– Commit changes
– Compare revisions
– ...
Git is Fast
2. Because it uses DAG-Storage over a
unique Content-Addressable File
System
Version 1

Delta
Storage

A
B
C
Version 1

Delta
Storage

Version 2

A

Δ A1

B
C

Δ C1
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 3

B
C

Δ C1

Δ C2
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 3

Δ A2

B
C

Version 4

Δ B1
Δ C1

Δ C2
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 3

Δ B1
Δ C1

Version 5

Δ A2

B
C

Version 4

Δ C2

Δ B2
Δ C3
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 1

A
B
C

Version 4

Δ B1
Δ C1

Version 5

Δ A2

B
C

DAG
Storage

V...
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 4

Δ B1
Δ C1

Version 1

Version 2

A

A1

B

B

C

C1

Version 5

Δ...
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 3

Version 5

Δ A2

B

Δ B1

C

Δ C1

Δ C2

Version 1

DAG
Storage

...
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 3

Version 4

Δ A2

B

Δ B1

C

Δ C1

Δ C2

Version 1

DAG
Storage

...
Version 1

Delta
Storage

Version 2

A

Δ A1

Version 3

Version 4

Version 5

Δ A2

B

Δ B1

Δ B2

C

Δ C2

Version 1

DA...
Git Object Database
blob

tree

commit

tag
Git Object Database
blob
tree
commit
tag

$
$
$
$

mkdir project
cd project
git init
tree
project/
└── .git
├── branches
├...
Git Object Database
blob
tree
commit
tag

$
$
$
$

mkdir project
cd project
git init
tree
Let’s ignore
the rest for now

p...
Git Object Database
blob
tree
commit

$
$
$
$

mkdir project
cd project
git init
tree
project/
└── .git

tag

Git Object D...
Git Object Database
$ echo hello > README

blob
tree
commit
tag
project/
├── .git
└── README

hello
Git Object Database
Git Object Database
$ echo hello > README
$ git add README

blob
tree
commit
tag
project/
├── .git
└── README

blob 60
hel...
Git Object Database
$ echo hello > README
$ git add README

blob

$ find .git/objects –type f
.git/objects/ce/013625030ba8...
Git Object Database
$ echo hello > README
$ git add README

blob

$ find .git/objects –type f
.git/objects/ce/013625030ba8...
Git Object Database
$ echo hello > README
$ git add README

blob
tree

$ find .git/objects –type f
.git/objects/ce/0136250...
Git Object Database
$ echo hello > README
$ git add README

blob
tree

$ find .git/objects –type f
.git/objects/ce/0136250...
Git Object Database
blob
tree

Blob = Content
High reuse (like all Git objects)

commit
tag
project/
├── .git
└── README

...
Git Object Database
blob
tree
commit
tag

$ cp README file2.txt (copy REAME)
$ echo test > file3.txt (create file3.txt)
$ ...
Git Object Database
blob

New Contents  New Blobs
 Files in a content-addressable FS

tree
commit
tag

Other Git Objects...
Git Object Database
blob
tree
commit
tag

$ git commit –m "Mon premier commit"
$ git log
commit 8e8eb678d9512d421e590350e3...
Git Object Database
blob
tree
commit
tag

$ git commit –m "Mon premier commit"
$ git log
commit 8e8eb678d9512d421e590350e3...
Git Object Database
./
README

blob

file2.txt
file3.txt

tree

tree
commit
tag

├──
│
├──
│
├──
│
├──
│

8e
└──
91
└──
9d...
blob
tree
commit

Git Object Database

tag

Objects
./

tree
README

…

file2.txt

blob 60

91/dc8d5

file3.txt

ce/01362
...
blob
tree
commit

Git Object Database

tag

Objects
./

tree

91/dc8d5

README

…

file2.txt

blob 60

file3.txt

ce/01362...
blob
tree
commit

Git Object Database

tag

Objects
Commit
8e8eb67

commit …
…
./

Tree xx0
README

blob 60

91/dc8d5

…

...
blob
tree

A Second Commit

commit
tag

New point in history, with a parent

$ mkdir doc
$ git mv file2.txt doc
$ git mv f...
Tags mark an important point
blob
tree

Tag = Pointer on a commit
+ label
+ [annotation]

commit
tag

- Releases
- Develop...
Git Object Database
blob

tree

commit

tag

So, everything Git stores are files in a
Content-Addressable File System
HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob
HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob
HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob
HEAD

tag

branch

commit

commit

commit

tree

tree

tree

tree

blob

tree

tree

blob

tree

blob

blob

blob
Git Object Database
blob

tree

commit

tag

So, everything Git stores are files in a
Content-Addressable File System
This makes Git Fast
• Restore an arbitrary version
– Git: checkout a hash = O(1)
– SVN: diffs between n last commits = O(n...
Some Benchmarking
Operation

Git

SVN

Add, commit and push 113 modified files (2164+, 2259-)

0.64

2.60

4x

Add, commit...
Git is…

Distributed
Fast
Reliable
Git is Reliable
1. Because it’s Distributed 
– Single dev with a remote?  2 copies (local,
remote)
– .git/ has it all

2...
Using Git

Working
Directory
Untracked

Staging
Area

Local
Repo

Remote
Repo
Using Git
Unique to Git

Working
Directory
Untracked

Staging
Area

Local
Repo

Remote
Repo
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git clone <url> [alias]

$ git clone https://github.com/...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git clone <url> [alias]

$ git clone https://github.com/...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git clone <url> [alias]

$ git remote –v
origin https://...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git clone <url> [alias]

$ git remote –v
origin https://...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git branch –a
* master
remotes/origin/HEAD -> origin/m...
origin

Working
Directory

Staging
Area

Local
Repo

$ git branch –a
crazy-idea
* master
remotes/origin/HEAD -> origin/mas...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git checkout <branch>

$ git branch –a
* crazy-idea
mast...
origin

Working
Directory

Staging
Area

Local
Repo

$ git status
# On branch crazy-idea
nothing to commit (working direct...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git status
# On branch crazy-idea
# Changes not staged...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git status
# On branch crazy-idea
# Changes not staged...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git status
# On branch crazy-idea
# Changes not staged...
origin

Working
Directory

Staging
Area

Local
Repo

git add <file>

$ git add core/net/rpl/rpl.c

« Stage » changes

HEAD...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git status
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

# On branc...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git status
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

# On branc...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git commit –m <message>

$ git commit –m "my crazy idea ...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git status
# On branch crazy-idea
# Changes not staged...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git add <file>

Untracked

Track untracked content

$ gi...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git commit –am <message>

+
$ git add core/net/newfile.c...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git checkout <branch>
$ git checkout master

HEAD

HEAD
...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

Has the project been updated?
Let’s fetch the changes
Ou...
Merges are done LOCALLY!
“Git push failed, To prevent from
losing history, non-fast forward
updates were rejected”

Not a...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo
git fetch origin

$ git checkout master
$ git fetch origi...
origin

Working
Directory

Staging
Area

$ git checkout master
$ git fetch origin
424a7b2..abcdef0 master

Local
Repo

Rem...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

$ git merge crazy-idea
Merge made by the 'recursive' str...
origin

Working
Directory

Staging
Area

Local
Repo

Remote
Repo

git push [remote] [branch]

OK, now we can push
$ git pu...
origin

Working
Directory

Staging
Area

Local
Repo

git remote add <alias> <url>

Remote
Repo
Remote
Repo

$ git remote a...
origin

Working
Directory

Staging
Area

Local
Repo

git push [remote] [branch]

Remote
Repo
Remote
Repo

$ git remote add...
origin

Working
Directory

Staging
Area

Local
Repo

git push [remote] [branch]

Remote
Repo
Remote
Repo

$ git remote add...
Before the push

HEAD
crazy-idea

8b5b2bd

704309c

424a7b2

4c5bae0

master

2cac7e2

origin/master
origin/HEAD

git push...
Now our contribution is public
Ready to be merged
8b5b2bd

704309c

424a7b2

4c5bae0

HEAD
crazy-idea

master

2cac7e2

or...
Now our contribution is public
Ready to be merged
8b5b2bd

704309c

424a7b2

4c5bae0

HEAD
crazy-idea

master

2cac7e2

or...
Jan Krüger’s Cheat Sheet
http://jan-krueger.net/git
Git LOVES branches, and so should you
Git = agile programming
Typical Workday
master

A

HEAD
long-feature

B

C

D
Git = agile programming
Typical Workday
master

A

HEAD
long-feature

B

C

D

+ Local Changes
Git = agile programming
Typical Workday
master

A

B

C
Long feature

D
Git = agile programming
Typical Workday
master

A

HEAD

Don’t Panic!!
git stash

long-feature

B

C

D

Local Changes
Git = agile programming
Typical Workday
master

A
long-feature

hotfix
HEAD

B

C

D

git branch hotfix
== git checkout –b...
Git = agile programming
Typical Workday
master

A
long-feature

B

C

E
git add
git commit
…

D

F
hotfix
HEAD
Git = agile programming
Typical Workday

HEAD
master

A

G
long-feature

B

C

E

D

F
hotfix

git checkout master
git mer...
Git = agile programming
Typical Workday
A

G

B

C

E

D

F

HOTFIX
Git = agile programming
Typical Workday

HEAD
master

A

G
E

F
hotfix

B

C

D
long-feature
Git = agile programming
Typical Workday
master

A

G
E

F
git checkout long-feature

hotfix

B

C

D
long-feature
HEAD
Git = agile programming
Typical Workday
master

A

G
E

F
hotfix

B

C

D

+ Local Changes

long-feature
HEAD

git checkou...
Git = agile programming
Typical Workday
master

A

G
E

F
hotfix

B

C

D

H
long-feature
HEAD

Keep working
Git = agile programming
Typical Workday
master

A

G
E

F
hotfix

B

C

D

H

I
long-feature
HEAD

Grab your fix:

git mer...
Re-Writing History
2cac7e2

« Code style »

4c5bae0

« ISSUUEE #3255 »

424a7b2

« More stuff on #2342 »

704309c

« Committing missing files...
Squashing commits
2cac7e2

« Code style »

4c5bae0

« ISSUUEE #3255 »

424a7b2

« More stuff on #2342 »

704309c

« Commit...
Squashing commits
12fff12

« Code style »

7434b12

« ISSUUEE #3255 »

ea3222c

« Resolves issue #2342,
More text describi...
Squashing commits
12fff12

« Code style »

Child commits affected!
7434b12

« ISSUUEE #3255 »

ea3222c

« Resolves issue #...
Squashing commits
12fff12

« Code style »

7434b12

« ISSUUEE #3255 »

8b5b2bd

« Resolves issue #2342,
More text describi...
Squashing commits
1212121

« Code style »

9876543

« Resolves issue #3255 »

8b5b2bd

« Resolves issue #2342,
More text d...
1212121

« Code style »

9876543

« Resolves issue #3255 »

8b5b2bd

« Resolves issue #2342,
More text describing the fix ...
Cherry-Picking
“Given one or more existing commits, apply the change each
one introduces, recording a new commit for each....
Cherry-Picking
“Given one or more existing commits, apply the change each
one introduces, recording a new commit for each....
Cherry-Picking
“Given one or more existing commits, apply the change each
one introduces, recording a new commit for each....
Don’t miss out on…
•
•
•
•

git
git
git
git

add –p
blame
diff
reset (soft/normal/hard)
Working together with Git
• « Workflow » ?
– How to structure a repository
• Branches and their interactions
• How the pro...
Working together with Git
• « Workflow » ?

–How to structure a repository
• Branches and their interactions
• How the pro...
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/

• Branche « master » = releases
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/

• Branche « master » = releases
• Branche « develop » = u...
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/

• Branche « master » = releases
• Branche « develop » = u...
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/

• Branche « master » = releases
• Branche « develop » = u...
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/

• Branche « master » = releases
• Branche « develop » = u...
GitFlow
http://nvie.com/posts/a-successful-git-branching-model/

• Branche « master » = releases
• Branche « develop » = u...
Working together with Git
• « Workflow » ?
– How to structure a repository
• Branches and their interactions
• How the pro...
Integration Manager Workflow
organisation/project
Blessed
Repository

Alice
Public

Bob
Public

Charlie
Public

The Boss

...
Dictator & Lieutenants Workflow
« Network of Trust » (Linux)

Dictator

torvalds/linux
Blessed
Repository

Lieutenants

Pl...
Getting Started with Git
• Book: Pro Git. www.git-scm.com
• Selected Tutorials:
– Git Immersion http://gitimmersion.com/
–...
Références
• Torvalds, L. Git. Google Tech Talk, 14-05-2007
• Shacon, S. Pro Git. git-scm.org
That's (g)it! par Sébastien Dawans CETIC
Upcoming SlideShare
Loading in …5
×

That's (g)it! par Sébastien Dawans CETIC

876 views

Published on

Présentation de GIT par Sébastien Dawans, Senior Engineer R&D au Cetic. http://www.cetic.be
Présenté le 26 Novembre 2013 à Louvain-la-Neuve

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
876
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
16
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

That's (g)it! par Sébastien Dawans CETIC

  1. 1. Git: Contrôle des versions, gestion des sources et bien plus encore... Session 1 - That’s (g)it ! Sébastien DAWANS 26/11/2013 © CETIC – www.cetic.be
  2. 2. About me… Internet of Things Internet 6LBR WSN http://cetic.github.io/6lbr www.cetic.be/6lbr (FR!) http://cetic.github.io/foren6
  3. 3. About me… Internet of Things Internet 6LBR Powered by Git ! WSN http://cetic.github.io/6lbr www.cetic.be/6lbr (FR!) http://cetic.github.io/foren6
  4. 4. S C M «S C ource ode oftware anagement onfiguration M anagement »
  5. 5. S C M «S C ource ode oftware & anagement onfiguration M anagement »
  6. 6. S C M «S C ource ode oftware & anagement onfiguration M anagement »
  7. 7. S C M «S C ource ode oftware & anagement onfiguration M anagement » Durée?
  8. 8. S C M «S C ource ode oftware & anagement onfiguration M anagement » Durée?
  9. 9. S C M «S C ource ode oftware & anagement onfiguration M anagement « branch » » Durée?
  10. 10. S C M «S C ource ode oftware & anagement onfiguration M anagement « branch » » Durée?
  11. 11. S C M «S C ource ode oftware & anagement onfiguration M anagement « branch » » Durée?
  12. 12. S C M «S C ource ode oftware & anagement onfiguration M anagement « branch » » Durée?
  13. 13. S C M «S C ource ode oftware & anagement onfiguration M anagement « branch » » Durée?
  14. 14. S C M «S C ource ode oftware & anagement onfiguration M anagement « branch » » Durée? « merge »
  15. 15. Panorama des SCM
  16. 16. Un peu d’histoire… 2002 1991 Manual tarballs, patches, mails « Much superior source control management system than CVS is »
  17. 17. Un peu d’histoire… 2002 1991 Manual tarballs, patches, mails « Much superior source control management system than CVS is » 2005 Bitkeeper Controversé car commercial Does the job right! Conditions: • No reverse-engineering • No development of competing solution
  18. 18. Un peu d’histoire… 2002 1991 Manual tarballs, patches, mails « Much superior source control management system than CVS is » Aujourd’hui 2005 Bitkeeper Controversé car commercial Does the job right! Conditions: • No reverse-engineering • No development of competing solution Git • Linus Torvals • Junio C Hamano
  19. 19. not an evolution rcs cvs svn git
  20. 20. not an evolution rcs cvs svn git
  21. 21. Git is… Distributed Fast Reliable
  22. 22. Centralized SCM Central CVS/SVN Dan ‘The Boss’ Alice Bob Charlie
  23. 23. Centralized SCM Central CVS/SVN Single Point of Failure Dan ‘The Boss’ Alice Bob Charlie
  24. 24. Centralized SCM Central CVS/SVN Network (slow) Single Point of Failure Dan ‘The Boss’ Alice Bob Charlie
  25. 25. Centralized SCM Central CVS/SVN Network (slow) Single Point of Failure Dan ‘The Boss’ Alice Bob Charlie Access Rights?
  26. 26. Git is Distributed Dan The Boss Charlie Alice Bob
  27. 27. Git is Distributed No a priori structure Dan The Boss Charlie Alice Bob
  28. 28. Git is Distributed No a priori structure Dan The Boss Charlie Alice Bob But Git ≠ Anarchy
  29. 29. Git is Distributed A very common practice: Sharing via user-owned repos Dan Public Dan The Boss Charlie Charlie Public Alice Public Alice Bob Bob Public
  30. 30. Git is Distributed A very common practice: Sharing via user-owned repos RD/WR Dan Public Dan The Boss Charlie Charlie Public Bob Bob Public READ ONLY Alice Public Alice
  31. 31. Git is Distributed A very common practice: Sharing via user-owned repos Dan Public Charlie Public Where to host these? Alice Public Bob Public
  32. 32. Git is Distributed Shared Repositories Dan Public Charlie Public Alice Public Bob Public « In-House », entreprise-local • Pure Git • Assisted: Gitosis/Gitlite • Web-based:
  33. 33. Git is Distributed Shared Repositories Dan Public Charlie Public Alice Public Bob Public « In-House », entreprise-local • Pure Git • Assisted: Gitosis/Gitlite • Web-based: Hosted • Private/Public (often, private = €)
  34. 34. Distributed Workflow Example Integration-Manager
  35. 35. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Alice Bob Dan The Boss
  36. 36. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Only Dan may WRITE Alice Bob Dan The Boss
  37. 37. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Other developers only READ Alice Bob Dan The Boss
  38. 38. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Alice Public Bob Public develop, commit Alice Bob Dan The Boss
  39. 39. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Alice Public Bob Public Share Features Alice Bob Dan The Boss
  40. 40. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Alice Public Bob Public Alice Bob Integrate Features Dan The Boss
  41. 41. Distributed Workflow Example « Integration-Manager » (Dan) Blessed Repo Alice Public Bob Public New Release Alice Bob Dan The Boss
  42. 42. Distributed Workflow Example Integration-Manager Dictator & Lieutenants
  43. 43. Dictator & Lieutenants Workflow « Network of Trust » (Linux) Dictator torvalds/linux Blessed Repository Lieutenants Plebs
  44. 44. Git is… Distributed Fast Reliable
  45. 45. Git is Fast 1. Because it’s distributed: No network overhead for daily operations: – Commit changes – Compare revisions – View the history – Create a branch – Switch branches – Merge branches – … and many more Alice Alice Public
  46. 46. Git is Fast 1. Because it’s distributed: No network overhead for daily operations: – Commit changes – Compare revisions – View the history – Create a branch – Switch branches – Merge branches – … and many more Alice 100% local Alice Public
  47. 47. Git is Fast 1. Because it’s distributed: No network overhead for daily operations: – Commit changes – Compare revisions – View the history – Create a branch – Switch branches – Merge branches – … and many more Alice 100% local local = fast ? Alice Public
  48. 48. Git is Fast 2. Because it uses DAG-Storage over a unique Content-Addressable File System
  49. 49. Version 1 Delta Storage A B C
  50. 50. Version 1 Delta Storage Version 2 A Δ A1 B C Δ C1
  51. 51. Version 1 Delta Storage Version 2 A Δ A1 Version 3 B C Δ C1 Δ C2
  52. 52. Version 1 Delta Storage Version 2 A Δ A1 Version 3 Δ A2 B C Version 4 Δ B1 Δ C1 Δ C2
  53. 53. Version 1 Delta Storage Version 2 A Δ A1 Version 3 Δ B1 Δ C1 Version 5 Δ A2 B C Version 4 Δ C2 Δ B2 Δ C3
  54. 54. Version 1 Delta Storage Version 2 A Δ A1 Version 1 A B C Version 4 Δ B1 Δ C1 Version 5 Δ A2 B C DAG Storage Version 3 Δ C2 Δ B2 Δ C3
  55. 55. Version 1 Delta Storage Version 2 A Δ A1 Version 4 Δ B1 Δ C1 Version 1 Version 2 A A1 B B C C1 Version 5 Δ A2 B C DAG Storage Version 3 Δ C2 Δ B2 Δ C3
  56. 56. Version 1 Delta Storage Version 2 A Δ A1 Version 3 Version 5 Δ A2 B Δ B1 C Δ C1 Δ C2 Version 1 DAG Storage Version 4 Version 2 Version 3 A A1 A1 B B B C C1 C2 Δ B2 Δ C3
  57. 57. Version 1 Delta Storage Version 2 A Δ A1 Version 3 Version 4 Δ A2 B Δ B1 C Δ C1 Δ C2 Version 1 DAG Storage Version 5 Version 2 Version 3 Version 4 A A1 A1 A2 B B B B1 C C1 C2 C2 Δ B2 Δ C3
  58. 58. Version 1 Delta Storage Version 2 A Δ A1 Version 3 Version 4 Version 5 Δ A2 B Δ B1 Δ B2 C Δ C2 Version 1 DAG Storage Δ C1 Version 2 Version 3 Version 4 Version 5 A A1 A1 A2 A2 B B B B1 B2 C C1 C2 C2 C3 Δ C3
  59. 59. Git Object Database blob tree commit tag
  60. 60. Git Object Database blob tree commit tag $ $ $ $ mkdir project cd project git init tree project/ └── .git ├── branches ├── config ├── description ├── HEAD ├── hooks ├── objects └── refs
  61. 61. Git Object Database blob tree commit tag $ $ $ $ mkdir project cd project git init tree Let’s ignore the rest for now project/ └── .git ├── branches ├── config ├── description ├── HEAD ├── hooks ├── objects └── refs Git Object Database
  62. 62. Git Object Database blob tree commit $ $ $ $ mkdir project cd project git init tree project/ └── .git tag Git Object Database
  63. 63. Git Object Database $ echo hello > README blob tree commit tag project/ ├── .git └── README hello Git Object Database
  64. 64. Git Object Database $ echo hello > README $ git add README blob tree commit tag project/ ├── .git └── README blob 60 hello ce/01362 hello Git Object Database
  65. 65. Git Object Database $ echo hello > README $ git add README blob $ find .git/objects –type f .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a tree commit tag project/ ├── .git └── README blob 60 ce/01362 hello Git Object Database
  66. 66. Git Object Database $ echo hello > README $ git add README blob $ find .git/objects –type f .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a tree commit tag project/ ├── .git └── README blob 60 ce/01362 hello Git Object Database
  67. 67. Git Object Database $ echo hello > README $ git add README blob tree $ find .git/objects –type f .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a $ printf "blob 60hellon" | sha1sum ce013625030ba8dba906f756967f9e9ca394464a commit blob 60 tag SHA-1 - Blob path/name hello project/ ├── .git └── README blob 60 ce/01362 hello Git Object Database
  68. 68. Git Object Database $ echo hello > README $ git add README blob tree $ find .git/objects –type f .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a $ printf "blob 60hellon" | sha1sum ce013625030ba8dba906f756967f9e9ca394464a $ git cat-file –p ce013625 hello commit blob 60 tag - hello project/ ├── .git └── README SHA-1 compression (zlib) Blob path/name Contents (hellon) blob 60 ce/01362 hello Git Object Database
  69. 69. Git Object Database blob tree Blob = Content High reuse (like all Git objects) commit tag project/ ├── .git └── README blob 60 ce/01362 hello Git Object Database
  70. 70. Git Object Database blob tree commit tag $ cp README file2.txt (copy REAME) $ echo test > file3.txt (create file3.txt) $ git add file2.txt file3.txt contents of file3.txt $ find .git/objects –type f .git/objects/9d/aeafb9864cf43055ae93beb0afd6c7d144bfa4 .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a contents of README project/ ├── .git ├── file2.txt ├── file3.txt └── README = contents of file2.txt blob 50 9d/aeafb test blob 60 ce/01362 hello Git Object Database
  71. 71. Git Object Database blob New Contents  New Blobs  Files in a content-addressable FS tree commit tag Other Git Objects behave exactly the same way
  72. 72. Git Object Database blob tree commit tag $ git commit –m "Mon premier commit" $ git log commit 8e8eb678d9512d421e590350e3100dc51ead6b7a Author: Sébastien Dawans <sebastien.dawans@cetic.be> Date: Sun Apr 14 22:26:29 2013 +0200 Mon premier commit
  73. 73. Git Object Database blob tree commit tag $ git commit –m "Mon premier commit" $ git log commit 8e8eb678d9512d421e590350e3100dc51ead6b7a Author: Sébastien Dawans <sebastien.dawans@cetic.be> Date: Sun Apr 14 22:26:29 2013 +0200 Mon premier commit $ tree .git/objects/ .git/objects/ ├── 8e │ └── 8eb678d9512d421e590350e3100dc51ead6b7a ├── 91 │ └── dc8d579f123918f3ac43af1e9377a97128763b ├── 9d │ └── aeafb9864cf43055ae93beb0afd6c7d144bfa4 ├── ce │ └── 013625030ba8dba906f756967f9e9ca394464a
  74. 74. Git Object Database ./ README blob file2.txt file3.txt tree tree commit tag ├── │ ├── │ ├── │ ├── │ 8e └── 91 └── 9d └── ce └── commit 8eb678d9512d421e590350e3100dc51ead6b7a dc8d579f123918f3ac43af1e9377a97128763b aeafb9864cf43055ae93beb0afd6c7d144bfa4 013625030ba8dba906f756967f9e9ca394464a blobs
  75. 75. blob tree commit Git Object Database tag Objects ./ tree README … file2.txt blob 60 91/dc8d5 file3.txt ce/01362 hello blob 50 test 9d/aeafb
  76. 76. blob tree commit Git Object Database tag Objects ./ tree 91/dc8d5 README … file2.txt blob 60 file3.txt ce/01362 hello blob 50 9d/aeafb test $ git cat-file -p 91dc8d5 100644 blob ce013625030ba8dba906f756967f9e9ca394464a 100644 blob ce013625030ba8dba906f756967f9e9ca394464a 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 README file2.txt file3.txt
  77. 77. blob tree commit Git Object Database tag Objects Commit 8e8eb67 commit … … ./ Tree xx0 README blob 60 91/dc8d5 … file2.txt file3.txt ce/01362 hello blob 50 test $ git cat-file -p 8e8eb67 tree 91dc8d579f123918f3ac43af1e9377a97128763b author Sébastien Dawans <sebastien.dawans@cetic.be> 1365971189 +0200 committer Sébastien Dawans <sebastien.dawans@cetic.be> 1365971189 +0200 Mon premier commit 91/dc8d5 9d/aeafb
  78. 78. blob tree A Second Commit commit tag New point in history, with a parent $ mkdir doc $ git mv file2.txt doc $ git mv file3.txt doc $ git commit -m "Deplacement de fichiers" [master fe88785] Deplacement de fichiers 2 files changed, 0 insertions(+), 0 deletions(-) rename file2.txt => doc/file2.txt (100%) rename file3.txt => doc/file3.txt (100%) 91dc8d5 91dc8d5 parent fe88785 2b425dd ce01362 b7f6192 fe88785 91dc8d5 2b425dd b7f6192 91dc8d5 ce01362 ce01362 new (high reuse) Objects 9daeafb evolution ce01362 9daeafb ce01362 9daeafb
  79. 79. Tags mark an important point blob tree Tag = Pointer on a commit + label + [annotation] commit tag - Releases - Development markers
  80. 80. Git Object Database blob tree commit tag So, everything Git stores are files in a Content-Addressable File System
  81. 81. HEAD tag branch commit commit commit tree tree tree tree blob tree tree blob tree blob blob blob
  82. 82. HEAD tag branch commit commit commit tree tree tree tree blob tree tree blob tree blob blob blob
  83. 83. HEAD tag branch commit commit commit tree tree tree tree blob tree tree blob tree blob blob blob
  84. 84. HEAD tag branch commit commit commit tree tree tree tree blob tree tree blob tree blob blob blob
  85. 85. Git Object Database blob tree commit tag So, everything Git stores are files in a Content-Addressable File System
  86. 86. This makes Git Fast • Restore an arbitrary version – Git: checkout a hash = O(1) – SVN: diffs between n last commits = O(n) • • • • Compare 2 revisions Reset Search through history And many more…
  87. 87. Some Benchmarking Operation Git SVN Add, commit and push 113 modified files (2164+, 2259-) 0.64 2.60 4x Add, commit and push 1000 1k images 1.53 24.70 16x Diff 187 changed files (1664+, 4859-) against last commit 0.25 1.09 4x Diff against 4 commits back (269 changed/3609+,6898-) 0.25 3.99 16x Diff two tags against each other 1.17 83.57 71x Log of the last 50 commits (19k of output) 0.01 0.38 31x Log of all commits (26,056 commits - 9.4M of output) 0.52 169.20 325x Log of the history of a single file 0.60 82.84 138x Pull of Commit A scenario (113 files changed, 2164+, 2259-) 0.90 2.82 3x Line annotation of a single file (array.c) 1.91 3.04 1x http://git-scm.com/about/small-and-fast
  88. 88. Git is… Distributed Fast Reliable
  89. 89. Git is Reliable 1. Because it’s Distributed  – Single dev with a remote?  2 copies (local, remote) – .git/ has it all 2. Checksums (SHA-1) for all objects Git uses – Detects data corruption – Guarantees Authenticity
  90. 90. Using Git Working Directory Untracked Staging Area Local Repo Remote Repo
  91. 91. Using Git Unique to Git Working Directory Untracked Staging Area Local Repo Remote Repo
  92. 92. origin Working Directory Staging Area Local Repo Remote Repo git clone <url> [alias] $ git clone https://github.com/contiki-os/contiki.git Cloning into 'contiki'... remote: Counting objects: 67870, done. remote: Compressing objects: 100% (13454/13454), done. remote: Total 67870 (delta 49179), reused 67358 (delta 48872) Receiving objects: 100% (67870/67870), 51.40 MiB | 5.15 MiB/s, done. Resolving deltas: 100% (49179/49179), done.
  93. 93. origin Working Directory Staging Area Local Repo Remote Repo git clone <url> [alias] $ git clone https://github.com/contiki-os/contiki.git Cloning into 'contiki'... remote: Counting objects: 67870, done. remote: Compressing objects: 100% (13454/13454), done. remote: Total 67870 (delta 49179), reused 67358 (delta 48872) Receiving objects: 100% (67870/67870), 51.40 MiB | 5.15 MiB/s, done. Resolving deltas: 100% (49179/49179), done. $ cd contiki $ ls –a Local Repo Working Directory . .. apps core cpu doc examples .git .gitignore LICENSE Makefile.include platform README README-BUILDING README-EXAMPLES regression-tests
  94. 94. origin Working Directory Staging Area Local Repo Remote Repo git clone <url> [alias] $ git remote –v origin https://github.com/contiki-os/contiki.git (fetch) origin https://github.com/contiki-os/contiki.git (push)
  95. 95. origin Working Directory Staging Area Local Repo Remote Repo git clone <url> [alias] $ git remote –v origin https://github.com/contiki-os/contiki.git (fetch) origin https://github.com/contiki-os/contiki.git (push) $ git branch * master Poke around $ git branch –a * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git log -n 3 --oneline 424a7b2 Merge pull request #202 from g-oikonomou/cc2538-minor-fixes 704309c Change the InfoPage Location of the IEEE address 8b5b2bd CC2538 Documentation typo and grammar fixes
  96. 96. origin Working Directory Staging Area Local Repo Remote Repo $ git branch –a * master remotes/origin/HEAD -> origin/master remotes/origin/master HEAD master 8b5b2bd 704309c Our working tree Our branch(es) 424a7b2 origin/master origin/HEAD Their branch(es) Their default branch
  97. 97. origin Working Directory Staging Area Local Repo $ git branch –a crazy-idea * master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch crazy-idea Let’s try Something HEAD master 8b5b2bd 704309c Remote Repo crazy-idea 424a7b2 origin/master origin/HEAD
  98. 98. origin Working Directory Staging Area Local Repo Remote Repo git checkout <branch> $ git branch –a * crazy-idea master remotes/origin/HEAD -> origin/master remotes/origin/master $ git branch crazy-idea $ git checkout crazy-idea HEAD master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD
  99. 99. origin Working Directory Staging Area Local Repo $ git status # On branch crazy-idea nothing to commit (working directory clean) ... hack your crazy idea add new files, modify others ... HEAD master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD Remote Repo
  100. 100. origin Working Directory Staging Area Local Repo Remote Repo $ git status # On branch crazy-idea # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: core/net/rpl/rpl.c # modified: core/net/tcpip.c # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # core/net/newfile.c no changes added to commit (use "git add" and/or "git commit -a") HEAD master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD
  101. 101. origin Working Directory Staging Area Local Repo Remote Repo $ git status # On branch crazy-idea # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # Modification # modified: core/net/rpl/rpl.c of tracked content # modified: core/net/tcpip.c # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # core/net/newfile.c no changes added to commit (use "git add" and/or "git commit -a") HEAD master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD
  102. 102. origin Working Directory Staging Area Local Repo Remote Repo $ git status # On branch crazy-idea # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # Modification # modified: core/net/rpl/rpl.c of tracked content # modified: core/net/tcpip.c # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # core/net/newfile.c New, untracked content no changes added to commit (use "git add" and/or "git commit -a") HEAD master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD
  103. 103. origin Working Directory Staging Area Local Repo git add <file> $ git add core/net/rpl/rpl.c « Stage » changes HEAD master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD Remote Repo
  104. 104. origin Working Directory Staging Area Local Repo Remote Repo $ git status # # # # # # # # # # # # # # # # # On branch crazy-idea Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: core/net/rpl/rpl.c Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: core/net/tcpip.c Untracked files: (use "git add <file>..." to include in what will be committed) HEAD core/net/newfile.c master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD
  105. 105. origin Working Directory Staging Area Local Repo Remote Repo $ git status # # # # # # # # # # # # # # # # # On branch crazy-idea Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: core/net/rpl/rpl.c Content of the next commit Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: core/net/tcpip.c Untracked files: (use "git add <file>..." to include in what will be committed) HEAD core/net/newfile.c master 8b5b2bd 704309c crazy-idea 424a7b2 origin/master origin/HEAD
  106. 106. origin Working Directory Staging Area Local Repo Remote Repo git commit –m <message> $ git commit –m "my crazy idea - part 1" [crazy-idea 4c5bae0] my crazy idea - part 1 1 file changed, 2 insertions(+) HEAD 4c5bae0 master 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD crazy-idea
  107. 107. origin Working Directory Staging Area Local Repo Remote Repo $ git status # On branch crazy-idea # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: core/net/tcpip.c # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # core/net/newfile.c no changes added to commit (use "git add" and/or "git commit -a") HEAD 4c5bae0 master 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD crazy-idea
  108. 108. origin Working Directory Staging Area Local Repo Remote Repo git add <file> Untracked Track untracked content $ git add core/net/newfile.c HEAD 4c5bae0 master 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD crazy-idea
  109. 109. origin Working Directory Staging Area Local Repo Remote Repo git commit –am <message> + $ git add core/net/newfile.c $ git commit –am "The rest of my crazy idea" [crazy-idea 2cac7e2] The rest of my crazy idea 2 files changed, 4 insertions(+) create mode 100644 core/net/newfile.c HEAD 4c5bae0 master 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD 2cac7e2 crazy-idea
  110. 110. origin Working Directory Staging Area Local Repo Remote Repo git checkout <branch> $ git checkout master HEAD HEAD master 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD 4c5bae0 2cac7e2 crazy-idea
  111. 111. origin Working Directory Staging Area Local Repo Remote Repo Has the project been updated? Let’s fetch the changes Our contribution HEAD master 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD 4c5bae0 2cac7e2 crazy-idea From last time we checked
  112. 112. Merges are done LOCALLY! “Git push failed, To prevent from losing history, non-fast forward updates were rejected” Not an error, but common-sense Files are rarely decorrelated
  113. 113. origin Working Directory Staging Area Local Repo Remote Repo git fetch origin $ git checkout master $ git fetch origin 424a7b2..abcdef0 master -> origin/master crazy-idea HEAD 4c5bae0 master … 704309c 424a7b2 abcdef0 origin/master origin/HEAD 2cac7e2
  114. 114. origin Working Directory Staging Area $ git checkout master $ git fetch origin 424a7b2..abcdef0 master Local Repo Remote Repo -> origin/master $ git merge origin/master crazy-idea 4c5bae0 … 704309c 424a7b2 2cac7e2 abcdef0 origin/master origin/HEAD HEAD master “Apply remote changes to our local master”
  115. 115. origin Working Directory Staging Area Local Repo Remote Repo $ git merge crazy-idea Merge made by the 'recursive' strategy. core/net/newfile.c | 2 ++ core/net/rpl/rpl.c | 2 ++ core/net/tcpip.c | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 core/net/newfile.c crazy-idea 4c5bae0 … 704309c 424a7b2 abcdef0 2cac7e2 aabbccd origin/master master origin/HEAD HEAD
  116. 116. origin Working Directory Staging Area Local Repo Remote Repo git push [remote] [branch] OK, now we can push $ git push origin master Still not permitted - Git is happy - But how can Contiki authors trust you?
  117. 117. origin Working Directory Staging Area Local Repo git remote add <alias> <url> Remote Repo Remote Repo $ git remote add github-cetic git@github.com:cetic/contiki.git
  118. 118. origin Working Directory Staging Area Local Repo git push [remote] [branch] Remote Repo Remote Repo $ git remote add github-cetic git@github.com:cetic/contiki.git $ git push github-cetic master OK
  119. 119. origin Working Directory Staging Area Local Repo git push [remote] [branch] Remote Repo Remote Repo $ git remote add cetic git@github.com:cetic/contiki.git $ git push cetic master OK New repo = 2 commands ! $ git push [remote] [branch[:alias]]
  120. 120. Before the push HEAD crazy-idea 8b5b2bd 704309c 424a7b2 4c5bae0 master 2cac7e2 origin/master origin/HEAD git push cetic master After the push 8b5b2bd 704309c HEAD crazy-idea 424a7b2 origin/master 4c5bae0 master 2cac7e2 cetic/master origin/HEAD new remote Is updated
  121. 121. Now our contribution is public Ready to be merged 8b5b2bd 704309c 424a7b2 4c5bae0 HEAD crazy-idea master 2cac7e2 origin/master origin/HEAD HEAD crazy-idea 8b5b2bd 704309c 424a7b2 origin/master origin/HEAD 4c5bae0 master 2cac7e2 cetic/master
  122. 122. Now our contribution is public Ready to be merged 8b5b2bd 704309c 424a7b2 4c5bae0 HEAD crazy-idea master 2cac7e2 origin/master origin/HEAD 1. Fetch+merge (done by owners of origin) 2. Pull-Request (involves both parties) crazy-idea 8b5b2bd 704309c 424a7b2 4c5bae0 HEAD master 2cac7e2 cetic/master origin/master origin/HEAD
  123. 123. Jan Krüger’s Cheat Sheet http://jan-krueger.net/git
  124. 124. Git LOVES branches, and so should you
  125. 125. Git = agile programming Typical Workday master A HEAD long-feature B C D
  126. 126. Git = agile programming Typical Workday master A HEAD long-feature B C D + Local Changes
  127. 127. Git = agile programming Typical Workday master A B C Long feature D
  128. 128. Git = agile programming Typical Workday master A HEAD Don’t Panic!! git stash long-feature B C D Local Changes
  129. 129. Git = agile programming Typical Workday master A long-feature hotfix HEAD B C D git branch hotfix == git checkout –b hotfix git checkout hotfix
  130. 130. Git = agile programming Typical Workday master A long-feature B C E git add git commit … D F hotfix HEAD
  131. 131. Git = agile programming Typical Workday HEAD master A G long-feature B C E D F hotfix git checkout master git merge hotfix git push origin master
  132. 132. Git = agile programming Typical Workday A G B C E D F HOTFIX
  133. 133. Git = agile programming Typical Workday HEAD master A G E F hotfix B C D long-feature
  134. 134. Git = agile programming Typical Workday master A G E F git checkout long-feature hotfix B C D long-feature HEAD
  135. 135. Git = agile programming Typical Workday master A G E F hotfix B C D + Local Changes long-feature HEAD git checkout long-feature git stash pop
  136. 136. Git = agile programming Typical Workday master A G E F hotfix B C D H long-feature HEAD Keep working
  137. 137. Git = agile programming Typical Workday master A G E F hotfix B C D H I long-feature HEAD Grab your fix: git merge master
  138. 138. Re-Writing History
  139. 139. 2cac7e2 « Code style » 4c5bae0 « ISSUUEE #3255 » 424a7b2 « More stuff on #2342 » 704309c « Committing missing files » 8b5b2bd « Fixing issue #2342 » abcdef0
  140. 140. Squashing commits 2cac7e2 « Code style » 4c5bae0 « ISSUUEE #3255 » 424a7b2 « More stuff on #2342 » 704309c « Committing missing files » 8b5b2bd « Fixing issue #2342 » abcdef0 squash
  141. 141. Squashing commits 12fff12 « Code style » 7434b12 « ISSUUEE #3255 » ea3222c « Resolves issue #2342, More text describing the fix » abcdef0 squashed
  142. 142. Squashing commits 12fff12 « Code style » Child commits affected! 7434b12 « ISSUUEE #3255 » ea3222c « Resolves issue #2342, More text describing the fix » abcdef0 squashed
  143. 143. Squashing commits 12fff12 « Code style » 7434b12 « ISSUUEE #3255 » 8b5b2bd « Resolves issue #2342, More text describing the fix » abcdef0 Amend the commit message
  144. 144. Squashing commits 1212121 « Code style » 9876543 « Resolves issue #3255 » 8b5b2bd « Resolves issue #2342, More text describing the fix » abcdef0 Clean History, can be merged
  145. 145. 1212121 « Code style » 9876543 « Resolves issue #3255 » 8b5b2bd « Resolves issue #2342, More text describing the fix » abcdef0
  146. 146. Cherry-Picking “Given one or more existing commits, apply the change each one introduces, recording a new commit for each.” D I C H B G A F abcdef0 M L git cherry-pick B C
  147. 147. Cherry-Picking “Given one or more existing commits, apply the change each one introduces, recording a new commit for each.” D I B’ C H B G A F abcdef0 M L git cherry-pick B C
  148. 148. Cherry-Picking “Given one or more existing commits, apply the change each one introduces, recording a new commit for each.” C’ D I B’ C H B G A F abcdef0 M L git cherry-pick B C
  149. 149. Don’t miss out on… • • • • git git git git add –p blame diff reset (soft/normal/hard)
  150. 150. Working together with Git • « Workflow » ? – How to structure a repository • Branches and their interactions • How the project moves forward – Organizing people • Who accesses what • How are contributions merged? Where? By who? • Responsibilities
  151. 151. Working together with Git • « Workflow » ? –How to structure a repository • Branches and their interactions • How the project moves forward – Organizing people • Who accesses what • How are contributions merged? Where? By who? • Responsibilities
  152. 152. GitFlow http://nvie.com/posts/a-successful-git-branching-model/
  153. 153. GitFlow http://nvie.com/posts/a-successful-git-branching-model/ • Branche « master » = releases
  154. 154. GitFlow http://nvie.com/posts/a-successful-git-branching-model/ • Branche « master » = releases • Branche « develop » = unstable
  155. 155. GitFlow http://nvie.com/posts/a-successful-git-branching-model/ • Branche « master » = releases • Branche « develop » = unstable • Branches: • Intégration Tests d’intégration + bugfixes
  156. 156. GitFlow http://nvie.com/posts/a-successful-git-branching-model/ • Branche « master » = releases • Branche « develop » = unstable • Branches: • Intégration • Features
  157. 157. GitFlow http://nvie.com/posts/a-successful-git-branching-model/ • Branche « master » = releases • Branche « develop » = unstable • Branches: • Intégration • Features • Hotfixes
  158. 158. GitFlow http://nvie.com/posts/a-successful-git-branching-model/ • Branche « master » = releases • Branche « develop » = unstable • Branches: • Intégration • Features • Hotfixes • Intégration au shell https://github.com/nvie/gitflow
  159. 159. Working together with Git • « Workflow » ? – How to structure a repository • Branches and their interactions • How the project moves forward – Organizing people • Who accesses what • How are contributions merged? Where? By who? • Responsibilities
  160. 160. Integration Manager Workflow organisation/project Blessed Repository Alice Public Bob Public Charlie Public The Boss Alice Bob Charlie
  161. 161. Dictator & Lieutenants Workflow « Network of Trust » (Linux) Dictator torvalds/linux Blessed Repository Lieutenants Plebs
  162. 162. Getting Started with Git • Book: Pro Git. www.git-scm.com • Selected Tutorials: – Git Immersion http://gitimmersion.com/ – Learn Git Branching (interactive) http://pcottle.github.io/learnGitBranching/ • More material: – teach.github.com • This presentation + cheat sheets and future stuff – https://github.com/cetic/git-slides
  163. 163. Références • Torvalds, L. Git. Google Tech Talk, 14-05-2007 • Shacon, S. Pro Git. git-scm.org

×