Distributed version control with git a brief...

Post on 13-Jun-2020

3 views 0 download

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

Oscar Nierstrasz

Distributed version control with git — a brief introduction

Thursday, September 15, 11

Why git?

Thursday, September 15, 11

Bob

Thursday, September 15, 11

Bob Carol

Thursday, September 15, 11

Bob Carol

TedAlice

Thursday, September 15, 11

Bob Carol

TedAlice

A recipe for disaster!Thursday, September 15, 11

The git object model

Thursday, September 15, 11

blob

A “blob” is content under version control (a file)

Thursday, September 15, 11

You can have trees of blobs(directories of files)

blobblob

tree

treeblob

Thursday, September 15, 11

A “commit” is a tree of blobs(a set of changes)

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

Most commits modify (or merge) earlier

commitscommit

blob

tree

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

You can “tag” an interesting commit

commit

blob

tree

tag

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

A graph of commits may belong to a branch

commit

blob

tree

tag

branch

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

commit

blob

tree

tag

HEAD

branch

blob

commit

blob

tree

treeblob

“HEAD “is the current branch

Thursday, September 15, 11

Let’s focus on commits and branches

commit

HEAD

branch

commit

Thursday, September 15, 11

Basic git

Thursday, September 15, 11

mkdir repocd repogit init

Create a git repo

C0

HEAD

master

Thursday, September 15, 11

git add …

Tell git to “stage” changes

C0

HEAD

master

Thursday, September 15, 11

C1

HEAD

master

git commit …

Commit your changes

C0

Thursday, September 15, 11

Collaborating

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

master

C1

C0

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git clone …

git clone …

mastermastermaster

C1

C0

C1

C0

C1

C0

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git add …git commit …

git add …git commit …

mastermastermaster

C0

C1

C0

C1

C1

C0

C2 C3

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git pull

(nothing new to pull)

mastermastermaster

C0

C2 C3

C1

C0

C1

C1

C0

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git push

mastermastermaster

C0

C2

C1

C0

C3

C1

C0

C2

C1

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git fetch

mastermastermaster

C0

C2 C2

C1

C0

C3

C1

C0

C2

C1

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git merge

NB: git pull = fetch + merge

C3

master

C1

C0

C2

mastermaster

C0

C2 C2

C1

C0

C1

C4

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git push

C3

master

C1

C0

C2

master

C1

C0

C2

master

C0

C2

C3C1

C4C4

Thursday, September 15, 11

Public repoLocal repo

John Jane

Local repo

git pull

C3

master

C1

C0

C2C3

master

C1

C0

C2C3

master

C1

C0

C2

C4 C4C4

Thursday, September 15, 11

Branching and merging

Thursday, September 15, 11

“origin” refers to the remote repo

C1

master

C0

origin/master

HEAD

Thursday, September 15, 11

…git commit …

C1

master

C0

origin/master

HEAD

C2

Thursday, September 15, 11

git branch tryout

C1

master

C0

C2

tryout

origin/master

HEAD

Thursday, September 15, 11

git checkout tryout

NB: git checkout –b … = branch + checkout

C1

master

C0

C2

tryout

origin/master

HEAD

Thursday, September 15, 11

git commit …

C1

master

C0

C2

tryout

origin/master

HEAD

C3

Thursday, September 15, 11

git fetch origin

C1

master

C0

C2

tryout

C3

origin/idea

origin/master

HEAD

C4

C5

C6

Thursday, September 15, 11

git merge origin/master origin/idea

C1

master

C0

C2

tryout

C3

C4

C5

C6

origin/idea

origin/master

HEAD

C7

Thursday, September 15, 11

git checkout master

C1

master

C0

C2

tryoutHEAD

C3

C4

C5

C6

origin/idea

C7

origin/master

Thursday, September 15, 11

git merge

C1

master

C0

C2

tryoutHEAD

C3

C4

C5

C6

origin/idea

C7

origin/master

C8

Thursday, September 15, 11

C1

master

origin/master

C0

C2

tryout

git push

HEAD

C3

C4

C5

C6

origin/idea

C8C7

Thursday, September 15, 11

More to git

Thursday, September 15, 11

More to git …

> Merging and mergetool> Squashing commits when merging> Resolving conflicts> User authentication with ssh> gitx and other graphical tools> git configure — remembering your name> git remote — multiple remote repos> github — an open source public repo> …

42

Thursday, September 15, 11

Resources

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

https://github.com/

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

Thursday, September 15, 11

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.

Thursday, September 15, 11