Distributed version control with git a brief...

77
Andrei Chis Distributed version control with git — a brief introduction based on slides by Oscar Nierstrasz

Transcript of Distributed version control with git a brief...

Page 1: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Andrei Chis

Distributed version control with git — a brief introduction

based on slides by Oscar Nierstrasz

Page 2: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Why version control?

�2

Page 3: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�3

Bob

Why version control?

Page 4: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�4

Bob Carol

Why version control?

Page 5: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�5

Bob Carol

TedAlice

Why version control?

Page 6: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�6

Bob Carol

TedAlice

Why version control?

Page 7: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�7

Bob Carol

TedAlice

Why version control?

Page 8: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�8

Bob Carol

TedAlice

A recipe for disaster!

Why version control?

Page 9: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

�9

Cope with the confusion that happens when multiple people edit

the same files

Why version control?

Page 10: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Carol

Page 11: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Carol

Page 12: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Snapshot Version 1

Carol

Page 13: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Version 1

Carol

Page 14: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Snapshot

Version 1

Version 2Carol

Page 15: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Version 1

CarolVersion 2

Page 16: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Version 1

CarolVersion 2

Page 17: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Version 1

CarolVersion 2

SnapshotVersion 3

Page 18: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Version 1

CarolVersion 2

Version 3

Version 4

Version 5

Version 6

Version 1

Version 2

Version 3

Version 1

Version 2

Version 3

Version 1

Version 2

Version 3

Version 100

Version 101

Version 103

AliceTed

Page 19: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob

Repository

Version 1

CarolVersion 2

Version 3

Version 4

Version 5

Version 6

Version 1

Version 2

Version 3

Version 1

Version 2

Version 3

Version 1

Version 2

Version 3

Version 100

Version 101

Version 103

AliceTed

Can still lead to disaster!

Controlled evolution

Page 20: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

git

Page 21: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

gitTracks the history of a collection of files

Page 22: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

gitTracks the history of a collection of files

Can revert the collection of files to another version

Page 23: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

git

distributed version control

system

Page 24: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

What is acentralized version

control system?

Page 25: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

Page 26: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

checkout

Page 27: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

checkoutcheckout

Page 28: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

Page 29: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

commit

Page 30: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

updatecommit

Page 31: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

commit

Page 32: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

commit

Page 33: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

commit commitconflict

X

Page 34: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Central repository

commit commitconflict

X

you must update before every commit

Page 35: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

What is adistributed version

control system?

Page 36: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

Page 37: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

clone

Page 38: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

clone

local repository

clone

Page 39: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repository

Page 40: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

Page 41: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push

Page 42: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push pull

Page 43: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push

Page 44: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push

Page 45: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

pushcommit

Page 46: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

pushcommitpush

conflict

X

Page 47: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

pushcommitpush

conflict

X

you must pull before every push

Page 48: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

Page 49: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

Remote repository

(p2exercises)

Page 50: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

Remote repository

(p2exercises)

Page 51: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

git remote add p2exercises ...

Remote repository

(p2exercises)

Page 52: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

git remote add p2exercises ...

git pull p2exercises master

Remote repository

(p2exercises)

Page 53: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

Remote repository

(p2exercises)

Page 54: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

groupX

do not commit after the deadline; it leads to merge conflicts

Remote repository

(p2exercises)

Page 55: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Basic git

Page 56: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

commit

A “commit” is “a set of changes” to a “set of files”

Page 57: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

commitcommit

Most commits modify (or merge) earlier commits

Page 58: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

commit

branch

commit

A graph of commits may belong to a

branch

Page 59: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

commit

master

commit

master is the main branch

Page 60: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

commit

HEAD

master

commit

“HEAD “is the current branch

Page 61: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

mkdir repocd repogit init

Create a git repo

C0

HEAD

master

Page 62: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

git add …

Tell git to “stage” changes

C0

HEAD

master

Page 63: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

C1

HEAD

master

git commit …

Commit your changes

C0

Page 64: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Collaborating

Page 65: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

master

C1

C0

Page 66: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git clone …

git clone …

mastermastermaster

C1

C0

C1

C0

C1

C0

Page 67: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git add …git commit …

git add …git commit …

mastermastermaster

C0

C1

C0

C1

C1

C0

C2 C3

Page 68: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git pull

(nothing new to pull)

mastermastermaster

C0

C2 C3

C1

C0

C1

C1

C0

Page 69: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git push

mastermastermaster

C0

C2

C1

C0

C3

C1

C0

C2

C1

Page 70: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git pull

master

C1

C0

mastermaster

C0

C2 C2

C1

C0

C1

C3 C2

Page 71: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git pull

NB: git pull = fetch + merge

master

C1

C0

mastermaster

C0

C2 C2

C1

C0

C1

C4

C2C3

Page 72: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git push

C3

master

C1

C0

C2

master

C1

C0

C2

master

C0

C2

C3C1

C4C4

Page 73: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Public repoLocal repo

John Jane

Local repo

git pull

C3

master

C1

C0

C2C3

master

C1

C0

C2C3

master

C1

C0

C2

C4 C4C4

Page 74: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based
Page 75: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

to be continued

Page 76: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

Resources

http://book.git-scm.com/index.htmlhttp://git-scm.com/

https://github.com/

http://www.slideshare.net/chacon/getting-git http://oreilly.com/

Page 77: Distributed version control with git a brief introductionscg.unibe.ch/.../20-02-21-week_01-GitIntroduction.pdf · Distributed version control with git — a brief introduction based

http://creativecommons.org/licenses/by-sa/3.0/

Attribution-ShareAlike 3.0You are free:

▪ to copy, distribute, display, and perform the work▪ to make derivative works▪ to make commercial use of the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor.

Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

▪ For any reuse or distribution, you must make clear to others the license terms of this work.▪ Any of these conditions can be waived if you get permission from the copyright holder.

Your fair use and other rights are in no way affected by the above.