Distributed version control with git a brief...

Post on 21-Jun-2020

18 views 0 download

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

Andrei Chis

Distributed version control with git — a brief introduction

based on slides by Oscar Nierstrasz

Why version control?

�2

�3

Bob

Why version control?

�4

Bob Carol

Why version control?

�5

Bob Carol

TedAlice

Why version control?

�6

Bob Carol

TedAlice

Why version control?

�7

Bob Carol

TedAlice

Why version control?

�8

Bob Carol

TedAlice

A recipe for disaster!

Why version control?

�9

Cope with the confusion that happens when multiple people edit

the same files

Why version control?

Bob

Repository

Carol

Bob

Repository

Carol

Bob

Repository

Snapshot Version 1

Carol

Bob

Repository

Version 1

Carol

Bob

Repository

Snapshot

Version 1

Version 2Carol

Bob

Repository

Version 1

CarolVersion 2

Bob

Repository

Version 1

CarolVersion 2

Bob

Repository

Version 1

CarolVersion 2

SnapshotVersion 3

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

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

git

gitTracks the history of a collection of files

gitTracks the history of a collection of files

Can revert the collection of files to another version

git

distributed version control

system

What is acentralized version

control system?

Bob Carol

Central repository

Bob Carol

Central repository

checkout

Bob Carol

Central repository

checkoutcheckout

Bob Carol

Central repository

Bob Carol

Central repository

commit

Bob Carol

Central repository

updatecommit

Bob Carol

Central repository

commit

Bob Carol

Central repository

commit

Bob Carol

Central repository

commit commitconflict

X

Bob Carol

Central repository

commit commitconflict

X

you must update before every commit

What is adistributed version

control system?

Bob Carol

Remote repository(groupXY)

Bob Carol

Remote repository(groupXY)

local repository

clone

Bob Carol

Remote repository(groupXY)

local repository

clone

local repository

clone

Bob Carol

Remote repository(groupXY)

local repository

local repository

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push pull

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

push

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

pushcommit

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

pushcommitpush

conflict

X

Bob Carol

Remote repository(groupXY)

local repository

local repositorycommit

pushcommitpush

conflict

X

you must pull before every push

groupX

groupX

Remote repository

(p2exercises)

groupX

Remote repository

(p2exercises)

groupX

git remote add p2exercises ...

Remote repository

(p2exercises)

groupX

git remote add p2exercises ...

git pull p2exercises master

Remote repository

(p2exercises)

groupX

Remote repository

(p2exercises)

groupX

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

Remote repository

(p2exercises)

Basic git

commit

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

commitcommit

Most commits modify (or merge) earlier commits

commit

branch

commit

A graph of commits may belong to a

branch

commit

master

commit

master is the main branch

commit

HEAD

master

commit

“HEAD “is the current branch

mkdir repocd repogit init

Create a git repo

C0

HEAD

master

git add …

Tell git to “stage” changes

C0

HEAD

master

C1

HEAD

master

git commit …

Commit your changes

C0

Collaborating

Public repoLocal repo

John Jane

Local repo

master

C1

C0

Public repoLocal repo

John Jane

Local repo

git clone …

git clone …

mastermastermaster

C1

C0

C1

C0

C1

C0

Public repoLocal repo

John Jane

Local repo

git add …git commit …

git add …git commit …

mastermastermaster

C0

C1

C0

C1

C1

C0

C2 C3

Public repoLocal repo

John Jane

Local repo

git pull

(nothing new to pull)

mastermastermaster

C0

C2 C3

C1

C0

C1

C1

C0

Public repoLocal repo

John Jane

Local repo

git push

mastermastermaster

C0

C2

C1

C0

C3

C1

C0

C2

C1

Public repoLocal repo

John Jane

Local repo

git pull

master

C1

C0

mastermaster

C0

C2 C2

C1

C0

C1

C3 C2

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

Public repoLocal repo

John Jane

Local repo

git push

C3

master

C1

C0

C2

master

C1

C0

C2

master

C0

C2

C3C1

C4C4

Public repoLocal repo

John Jane

Local repo

git pull

C3

master

C1

C0

C2C3

master

C1

C0

C2C3

master

C1

C0

C2

C4 C4C4

to be continued

Resources

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

https://github.com/

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

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.