49
Joel Krebs Slides by Oscar Nierstrasz Distributed version control with git a brief introduction

Quick Introduction to git

Embed Size (px)

Citation preview

Page 1: Quick Introduction to git

Joel Krebs

Slides by Oscar Nierstrasz

Distributed version control with git — a brief introduction

Page 2: Quick Introduction to git

Why git?

Page 3: Quick Introduction to git

Bob

Page 4: Quick Introduction to git

Bob Carol

Page 5: Quick Introduction to git

Bob Carol

Ted Alice

Page 6: Quick Introduction to git

Bob Carol

Ted Alice

A recipe for disaster!

Page 7: Quick Introduction to git

What is git?

Page 8: Quick Introduction to git

> Distributed revision control system

> Originally developed by Linus Torvalds for the development of the Linux Kernel in 2005

> Focus on speed and efficiency

> Quite a unique design and therefore sometimes a bit scary and difficult to understand

Page 9: Quick Introduction to git

The git object model

Page 10: Quick Introduction to git

blob

A “blob” is content under

version control (a file)

Page 11: Quick Introduction to git

You can have trees of blobs

(directories of files)

blob

blob

tree

tree

blob

Page 12: Quick Introduction to git

A “commit” is a tree of blobs

(a set of changes)

blob

commit

blob

tree

tree

blob

Page 13: Quick Introduction to git

Most commits modify

(or merge) earlier

commits

commit

blob

tree

blob

commit

blob

tree

tree

blob

Page 14: Quick Introduction to git

You can “tag” an

interesting commit

commit

blob

tree

tag

blob

commit

blob

tree

tree

blob

Page 15: Quick Introduction to git

A graph of commits

may belong to a branch

commit

blob

tree

tag

branch

blob

commit

blob

tree

tree

blob

Page 16: Quick Introduction to git

commit

blob

tree

tag

HEAD

branch

blob

commit

blob

tree

tree

blob

“HEAD “is the

current branch

Page 17: Quick Introduction to git

Let’s focus on commits

and branches

commit

HEAD

branch

commit

Page 18: Quick Introduction to git

Basic git

Page 19: Quick Introduction to git

Create a git repo

C0

HEAD

master

Page 20: Quick Introduction to git

Tell git to “stage”

changes

C0

HEAD

master

Page 21: Quick Introduction to git

C1

HEAD

master Commit your

changes

C0

Page 22: Quick Introduction to git

Collaborating

Page 23: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

master

C1

C0

Page 24: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

master master master

C1

C0

C1

C0

C1

C0

Page 25: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

master master master

C0

C1

C0

C1

C1

C0

C2 C3

Page 26: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

(nothing new to pull)

master master master

C0

C2 C3

C1

C0

C1

C1

C0

Page 27: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

master master master

C0

C2

C1

C0

C3

C1

C0

C2

C1

Page 28: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

master master master

C0

C2 C2

C1

C0

C3

C1

C0

C2

C1

Page 29: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

NB: git pull = fetch + merge

C3

master

C1

C0

C2

master master

C0

C2 C2

C1

C0

C1

C4

Page 30: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

C3

master

C1

C0

C2

master

C1

C0

C2

master

C0

C2

C3 C1

C4 C4

Page 31: Quick Introduction to git

Public repo Local repo

John Jane

Local repo

C3

master

C1

C0

C2 C3

master

C1

C0

C2 C3

master

C1

C0

C2

C4 C4 C4

Page 32: Quick Introduction to git

Branching

and merging

Page 33: Quick Introduction to git

“origin” refers to the

remote repo

C1

master

C0

origin/master

HEAD

Page 34: Quick Introduction to git

C1

master

C0

origin/master

HEAD

C2

Page 35: Quick Introduction to git

C1

master

C0

C2

tryout

origin/master

HEAD

Page 36: Quick Introduction to git

NB: git checkout –b … =

branch + checkout

C1

master

C0

C2

tryout

origin/master

HEAD

Page 37: Quick Introduction to git

C1

master

C0

C2

tryout

origin/master

HEAD

C3

Page 38: Quick Introduction to git

C1

master

C0

C2

tryout

C3

origin/idea

origin/master

HEAD

C4

C5

C6

Page 39: Quick Introduction to git

C1

master

C0

C2

tryout

C3

C4

C5

C6

origin/idea

origin/master

HEAD

C7

Page 40: Quick Introduction to git

C1

master

C0

C2

tryout HEAD

C3

C4

C5

C6

origin/idea

C7

origin/master

Page 41: Quick Introduction to git

C1

master

C0

C2

tryout

HEAD

C3

C4

C5

C6

origin/idea

C7

origin/master

C8

Page 42: Quick Introduction to git

C1

master

origin/master

C0

C2

tryout

HEAD

C3

C4

C5

C6

origin/idea

C8 C7

Page 43: Quick Introduction to git

Overview git workflow

Local repository

Working directory

Index (cache)

Remote repository

fetch

pull

push

commit

add

checkout

HEAD

Page 44: Quick Introduction to git

Getting started

Page 45: Quick Introduction to git

> Follow instructions on P2 Blog for installation

> Send your ssh public key to [email protected]

> Create meaningful commits with according messages

> Hints that make your life easier:

—Create a .gitignore file

—Always pull before you push

—Don’t panic when merge conflicts occur

First steps

Page 46: Quick Introduction to git

More to git

Page 47: Quick Introduction to git

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

> …

Page 48: Quick Introduction to git

Resources

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

https://github.com/

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

http://gitready.com/