44
git r’ done! A brief introduction to distributed version control with git Oscar Nierstrasz — University of Bern — scg.unibe.ch

Git primer

Embed Size (px)

DESCRIPTION

A brief introduction to distributed version control with git. Shamelessly adapted from Scott Chacon's excellent "Getting Git" talk: http://www.slideshare.net/chacon/getting-git

Citation preview

Page 1: Git primer

git r’ done!

A brief introduction todistributed version control with git

Oscar Nierstrasz — University of Bern — scg.unibe.ch

Page 2: Git primer

Why git?

Page 3: Git primer

Bob

Page 4: Git primer

BobCarol

Page 5: Git primer

BobCarol

TedAlice

Page 6: Git primer

BobCarol

TedAlice

A recipe for disaster!

Page 7: Git primer

The git object model

Page 8: Git primer

blob

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

Page 9: Git primer

blob

blob

tree

tree

blob

You can have trees of blobs(directories of files)

Page 10: Git primer

blob

commit

blob

tree

tree

blob

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

Page 11: Git primer

commit

blob

tree

blob

commit

blob

tree

tree

blob

Most commits modify (or merge) earlier commits

Page 12: Git primer

commit

blob

tree

tag

blob

commit

blob

tree

tree

blob

You can “tag” an interesting commit

Page 13: Git primer

commit

blob

tree

tag

branch

blob

commit

blob

tree

tree

blob

A graph of commits may belong to a branch

Page 14: Git primer

commit

blob

tree

tag

HEAD

branch

blob

commit

blob

tree

tree

blob

“HEAD “is the current branch

Page 15: Git primer

commit

HEAD

branch

commit

Let’s focus on commits and branches

Page 16: Git primer

Basic git

Page 17: Git primer

mkdir repocd repogit init C0

HEAD

master

Create a git repo

Page 18: Git primer

C0

HEAD

master git add …

Tell git to “stage” changes

Page 19: Git primer

C1

HEAD

master

git commit …

Commit your changes

C0

Page 20: Git primer

Collaborating

Page 21: Git primer

Public repo

C1

master

C0

Local repo

John Jane

Local repo

Page 22: Git primer

Public repo

C1

master

C0

Local repo

John Jane

Local repo

git clone …

git clone …

C1

master

C0

C1

master

C0

Page 23: Git primer

Public repo

C1

master

C0

Local repo

John Jane

Local repo

git add …git commit …

C2

master

C1

C3

master

C1

C0C0

git add …git commit …

Page 24: Git primer

Public repo

C1

master

C0

Local repo

John Jane

Local repo

C2

master

C1

C3

master

C1

C0C0

git pull

(nothing new to pull)

Page 25: Git primer

Public repoLocal repo

John Jane

Local repo

C2

master

C1

C3

master

C1

C0C0

git push

C2

master

C1

C0

Page 26: Git primer

Public repoLocal repo

John Jane

Local repo

C2

master

C1

C3

master

C1

C0C0

git fetch

C2

master

C1

C0

C2

Page 27: Git primer

Public repoLocal repo

John Jane

Local repo

C2

master

C1 C3

master

C1

C0

C0

C2

master

C1

C0

C2

C4

git merge

NB: git pull = fetch + merge

Page 28: Git primer

Public repoLocal repo

John Jane

Local repo

C2

master

C1 C3

master

C1

C0

C0

C2

C4

git push

C3

master

C1

C0

C2

C4

Page 29: Git primer

Public repoLocal repo

John Jane

Local repo

C3

master

C1

C0

C2

C4

git pull

C3

master

C1

C0

C2

C4

C3

master

C1

C0

C2

C4

Page 30: Git primer

Branching and merging

Page 31: Git primer

C1

master

origin/master

C0

HEAD

“origin” refers to the remote repo

Page 32: Git primer

C1

master

origin/master

C0

HEAD

C2…git commit …

Page 33: Git primer

C1

master

origin/master

C0

HEAD

C2

git branch tryout

tryout

Page 34: Git primer

C1

master

origin/master

C0

C2

tryout

git checkout tryout

NB: git checkout –b … = branch + checkout

HEAD

Page 35: Git primer

C1

master

origin/master

C0

C2

tryout

git commit …

HEAD

C3

Page 36: Git primer

C1

master

origin/master

C0

C2

tryout

git fetch origin

HEAD

C3

C4

C5

C6 origin/idea

Page 37: Git primer

C1

master

origin/master

C0

C2

tryout

git merge origin/master origin/idea

HEAD

C3

C4

C5

C6

origin/idea

C7

Page 38: Git primer

C1

master

origin/master

C0

C2

tryout

git checkout master

HEAD

C3

C4

C5

C6

origin/idea

C7

Page 39: Git primer

C1

master

origin/master

C0

C2

tryout

git merge

HEAD

C3

C4

C5

C6

origin/idea

C7C8

Page 40: Git primer

C1

master

origin/master

C0

C2

tryout

git push

HEAD

C3

C4

C5

C6

origin/idea

C7C8

Page 41: Git primer

More to git

Page 42: Git primer

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 43: Git primer

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 44: Git primer

License

Attribution-ShareAlike 2.5You 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.

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