distributed version control with git a brief...

44
Oscar Nierstrasz Distributed version control with git — a brief introduction Thursday, September 15, 11

Upload: others

Post on 13-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Oscar Nierstrasz

Distributed version control with git — a brief introduction

Thursday, September 15, 11

Page 2: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Why git?

Thursday, September 15, 11

Page 3: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Bob

Thursday, September 15, 11

Page 4: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Bob Carol

Thursday, September 15, 11

Page 5: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Bob Carol

TedAlice

Thursday, September 15, 11

Page 6: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Bob Carol

TedAlice

A recipe for disaster!Thursday, September 15, 11

Page 7: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

The git object model

Thursday, September 15, 11

Page 8: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

blob

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

Thursday, September 15, 11

Page 9: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

You can have trees of blobs(directories of files)

blobblob

tree

treeblob

Thursday, September 15, 11

Page 10: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

Page 11: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Most commits modify (or merge) earlier

commitscommit

blob

tree

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

Page 12: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

You can “tag” an interesting commit

commit

blob

tree

tag

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

Page 13: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

A graph of commits may belong to a branch

commit

blob

tree

tag

branch

blob

commit

blob

tree

treeblob

Thursday, September 15, 11

Page 14: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

commit

blob

tree

tag

HEAD

branch

blob

commit

blob

tree

treeblob

“HEAD “is the current branch

Thursday, September 15, 11

Page 15: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Let’s focus on commits and branches

commit

HEAD

branch

commit

Thursday, September 15, 11

Page 16: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Basic git

Thursday, September 15, 11

Page 17: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

mkdir repocd repogit init

Create a git repo

C0

HEAD

master

Thursday, September 15, 11

Page 18: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git add …

Tell git to “stage” changes

C0

HEAD

master

Thursday, September 15, 11

Page 19: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

C1

HEAD

master

git commit …

Commit your changes

C0

Thursday, September 15, 11

Page 20: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Collaborating

Thursday, September 15, 11

Page 21: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Public repoLocal repo

John Jane

Local repo

master

C1

C0

Thursday, September 15, 11

Page 22: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Public repoLocal repo

John Jane

Local repo

git clone …

git clone …

mastermastermaster

C1

C0

C1

C0

C1

C0

Thursday, September 15, 11

Page 23: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 24: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 25: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Public repoLocal repo

John Jane

Local repo

git push

mastermastermaster

C0

C2

C1

C0

C3

C1

C0

C2

C1

Thursday, September 15, 11

Page 26: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Public repoLocal repo

John Jane

Local repo

git fetch

mastermastermaster

C0

C2 C2

C1

C0

C3

C1

C0

C2

C1

Thursday, September 15, 11

Page 27: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 28: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 29: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 30: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

Branching and merging

Thursday, September 15, 11

Page 31: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

“origin” refers to the remote repo

C1

master

C0

origin/master

HEAD

Thursday, September 15, 11

Page 32: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

…git commit …

C1

master

C0

origin/master

HEAD

C2

Thursday, September 15, 11

Page 33: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git branch tryout

C1

master

C0

C2

tryout

origin/master

HEAD

Thursday, September 15, 11

Page 34: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git checkout tryout

NB: git checkout –b … = branch + checkout

C1

master

C0

C2

tryout

origin/master

HEAD

Thursday, September 15, 11

Page 35: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git commit …

C1

master

C0

C2

tryout

origin/master

HEAD

C3

Thursday, September 15, 11

Page 36: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git fetch origin

C1

master

C0

C2

tryout

C3

origin/idea

origin/master

HEAD

C4

C5

C6

Thursday, September 15, 11

Page 37: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 38: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git checkout master

C1

master

C0

C2

tryoutHEAD

C3

C4

C5

C6

origin/idea

C7

origin/master

Thursday, September 15, 11

Page 39: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

git merge

C1

master

C0

C2

tryoutHEAD

C3

C4

C5

C6

origin/idea

C7

origin/master

C8

Thursday, September 15, 11

Page 40: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

C1

master

origin/master

C0

C2

tryout

git push

HEAD

C3

C4

C5

C6

origin/idea

C8C7

Thursday, September 15, 11

Page 41: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

More to git

Thursday, September 15, 11

Page 42: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 43: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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

Page 44: Distributed version control with git a brief introductionscg.unibe.ch/download/lectures/p2-2012/P2-01-Git.pdf · version control (a file) Thursday, September 15, 11. You can have

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