quick introduction to git
TRANSCRIPT
Joel Krebs
Slides by Oscar Nierstrasz
Distributed version control with git — a brief introduction
Why git?
Bob
Bob Carol
Bob Carol
Ted Alice
Bob Carol
Ted Alice
A recipe for disaster!
What is 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
The git object model
blob
A “blob” is content under
version control (a file)
You can have trees of blobs
(directories of files)
blob
blob
tree
tree
blob
A “commit” is a tree of blobs
(a set of changes)
blob
commit
blob
tree
tree
blob
Most commits modify
(or merge) earlier
commits
commit
blob
tree
blob
commit
blob
tree
tree
blob
You can “tag” an
interesting commit
commit
blob
tree
tag
blob
commit
blob
tree
tree
blob
A graph of commits
may belong to a branch
commit
blob
tree
tag
branch
blob
commit
blob
tree
tree
blob
commit
blob
tree
tag
HEAD
branch
blob
commit
blob
tree
tree
blob
“HEAD “is the
current branch
Let’s focus on commits
and branches
commit
HEAD
branch
commit
Basic git
Create a git repo
C0
HEAD
master
Tell git to “stage”
changes
C0
HEAD
master
C1
HEAD
master Commit your
changes
C0
Collaborating
Public repo Local repo
John Jane
Local repo
master
C1
C0
Public repo Local repo
John Jane
Local repo
master master master
C1
C0
C1
C0
C1
C0
Public repo Local repo
John Jane
Local repo
master master master
C0
C1
C0
C1
C1
C0
C2 C3
Public repo Local repo
John Jane
Local repo
(nothing new to pull)
master master master
C0
C2 C3
C1
C0
C1
C1
C0
Public repo Local repo
John Jane
Local repo
master master master
C0
C2
C1
C0
C3
C1
C0
C2
C1
Public repo Local repo
John Jane
Local repo
master master master
C0
C2 C2
C1
C0
C3
C1
C0
C2
C1
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
Public repo Local repo
John Jane
Local repo
C3
master
C1
C0
C2
master
C1
C0
C2
master
C0
C2
C3 C1
C4 C4
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
Branching
and merging
“origin” refers to the
remote repo
C1
master
C0
origin/master
HEAD
C1
master
C0
origin/master
HEAD
C2
C1
master
C0
C2
tryout
origin/master
HEAD
NB: git checkout –b … =
branch + checkout
C1
master
C0
C2
tryout
origin/master
HEAD
C1
master
C0
C2
tryout
origin/master
HEAD
C3
C1
master
C0
C2
tryout
C3
origin/idea
origin/master
HEAD
C4
C5
C6
C1
master
C0
C2
tryout
C3
C4
C5
C6
origin/idea
origin/master
HEAD
C7
C1
master
C0
C2
tryout HEAD
C3
C4
C5
C6
origin/idea
C7
origin/master
C1
master
C0
C2
tryout
HEAD
C3
C4
C5
C6
origin/idea
C7
origin/master
C8
C1
master
origin/master
C0
C2
tryout
HEAD
C3
C4
C5
C6
origin/idea
C8 C7
Overview git workflow
Local repository
Working directory
Index (cache)
Remote repository
fetch
pull
push
commit
add
checkout
HEAD
Getting started
> 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
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.html http://git-scm.com/
https://github.com/
http://www.slideshare.net/chacon/getting-git http://oreilly.com/
http://gitready.com/
http://creativecommons.org/licenses/by-sa/3.0/