Git primer

Post on 12-May-2015

3.668 views 0 download

Tags:

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

Transcript of Git primer

git r’ done!

A brief introduction todistributed version control with git

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

Why git?

Bob

BobCarol

BobCarol

TedAlice

BobCarol

TedAlice

A recipe for disaster!

The git object model

blob

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

blob

blob

tree

tree

blob

You can have trees of blobs(directories of files)

blob

commit

blob

tree

tree

blob

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

commit

blob

tree

blob

commit

blob

tree

tree

blob

Most commits modify (or merge) earlier commits

commit

blob

tree

tag

blob

commit

blob

tree

tree

blob

You can “tag” an interesting commit

commit

blob

tree

tag

branch

blob

commit

blob

tree

tree

blob

A graph of commits may belong to a branch

commit

blob

tree

tag

HEAD

branch

blob

commit

blob

tree

tree

blob

“HEAD “is the current branch

commit

HEAD

branch

commit

Let’s focus on commits and branches

Basic git

mkdir repocd repogit init C0

HEAD

master

Create a git repo

C0

HEAD

master git add …

Tell git to “stage” changes

C1

HEAD

master

git commit …

Commit your changes

C0

Collaborating

Public repo

C1

master

C0

Local repo

John Jane

Local repo

Public repo

C1

master

C0

Local repo

John Jane

Local repo

git clone …

git clone …

C1

master

C0

C1

master

C0

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 …

Public repo

C1

master

C0

Local repo

John Jane

Local repo

C2

master

C1

C3

master

C1

C0C0

git pull

(nothing new to pull)

Public repoLocal repo

John Jane

Local repo

C2

master

C1

C3

master

C1

C0C0

git push

C2

master

C1

C0

Public repoLocal repo

John Jane

Local repo

C2

master

C1

C3

master

C1

C0C0

git fetch

C2

master

C1

C0

C2

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

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

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

Branching and merging

C1

master

origin/master

C0

HEAD

“origin” refers to the remote repo

C1

master

origin/master

C0

HEAD

C2…git commit …

C1

master

origin/master

C0

HEAD

C2

git branch tryout

tryout

C1

master

origin/master

C0

C2

tryout

git checkout tryout

NB: git checkout –b … = branch + checkout

HEAD

C1

master

origin/master

C0

C2

tryout

git commit …

HEAD

C3

C1

master

origin/master

C0

C2

tryout

git fetch origin

HEAD

C3

C4

C5

C6 origin/idea

C1

master

origin/master

C0

C2

tryout

git merge origin/master origin/idea

HEAD

C3

C4

C5

C6

origin/idea

C7

C1

master

origin/master

C0

C2

tryout

git checkout master

HEAD

C3

C4

C5

C6

origin/idea

C7

C1

master

origin/master

C0

C2

tryout

git merge

HEAD

C3

C4

C5

C6

origin/idea

C7C8

C1

master

origin/master

C0

C2

tryout

git push

HEAD

C3

C4

C5

C6

origin/idea

C7C8

More 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• …

Resources

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

https://github.com/

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

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/