Git SCM

stefanprutianu 2,478 views 41 slides Oct 18, 2013
Slide 1
Slide 1 of 41
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41

About This Presentation

An introduction into SCM tools, git concepts and how to use git.


Slide Content

GIT SCM
@stefanprutianu

SCM?
Source Code Management
aka!
!
Version Control System !
aka!
!
Revision Control System

Why?
!because we need to keep track of changes:
!collaboration
!centralized SCMs: Subversion, CVS
!distributed SCMs: GIT, Mercurial
when? !
why? !
what was the content? !
who? (very important, right? :))

Centralized & Distributed
checkout!
commit!
revert!
merge!
tag!
branch!
lock!
conflict resolution.!
...

Centralized vs. Distributed
everyone has a full
copy - distributed!
works offline or
disconnected from a
server!
saves snapshots of data
it manages !
a commit operates over
the local repository
master copy in one
place!
single point of failure!
considers data as a list
of file -based changes
(initial version + deltas) !
a commit operates over
the central repository
centralized distributed

SVN model
Repository
Client 1 Client 2 Client n
Time
Version 1 Version 2
File A
File B
File C
Delta 1
Delta 1
Version 3
Delta 1
Version 4
Delta 2
Delta 2

GIT model
Central!
Repository
Client 1 !
(mirror)
Client 2!
(mirror)
Client n!
(mirror)
Time
Version 1 Version 2
File A
File B
File C
File A1
File C1
Version 3 Version 4
File A2
File B2File B File B1File A1 File C1 File C1

GIT --history
2005, Linux kernel maintenance (35000 files) !
Linus Torvalds!
written in C
"So I'm sorry, but for something like git, where efficiency was a primary !
objective, the "advantages" of C++ is just a huge mistake. The fact that !
we also piss off people who cannot see that is just a big additional !
advantage." (L.T.)
modern, robust, fast, distributed, great branching
system, complex merges, open source !
available on Mac, Windows, Linux
British slang for "pig headed, think they are always
correct, argumentative"

GIT --philosophy
a git repository is a....graph, Directed Acyclic Graph !
node = commit !
edge = pointers from child nodes to parent node(s) !
nodes are identified by SHA-1 hashes from: content change +
parent(s) commit identifier => speed !
a lot of the work done by git involves moving references
(labels) around => speed

GIT --philosophy
git references = labels assigned to commits !
several types: branch (local/remote), tag, stash !
references are stored in .git/refs/heads ( the SHA-1
identifier of the commit it points to, 41 bytes) !
there are references to references -> HEAD, for example,
which points to the current branch !
references make commits reachable

GIT --philosophy
fast forward merge

GIT --philosophy

GIT --concepts
git manages its content via 3 states: modified, staged,
committed
Workspace Staging !
area
Repository
Local repository
stage
unstage
commit
checkout

GIT --concepts
Workspace (working directory)
one version of the content, extracted from git database to be
used or modified

GIT --concepts
Staging area (index)
allows you to elect files/content that is going to participate in
the next commit!
you can see how the next snapshot would look like before
actually creating it - avoid mistakes !
allows you to break changes in workspace into more than 1
single commit

GIT --concepts
Repository
where object database and metadata is stored !
the .git folder inside your repository root folder

GIT --concepts
git manages its content via 3 4 states: modified,
staged, committed, stashed!
!
Stash
here you can save changes you want to keep but
not ready to commit yet !
stashes are in fact labeled nodes on the
repository graph

GIT --concepts
Stash
Local repository
Workspace Staging !
area
Repository
stage
unstage
commit
checkout
Stash
create
apply

GIT --concepts
Remote repository
git repository located on another machine, usually !
the local repository may be a mirror of the remote one !
write into it via push, read from it via pull & fetch

GIT --concepts
Remote repository
Local repository
Workspace
Staging !
area
Repository
Stash
Remote repository
Workspace
Staging !
area
Repository
Stash
push pull/fetch

GIT --concepts
GIT objects
blobs - contents of a file!
tree - directories of blobs or other trees !
commits - SHA-1 of a tree, parent commit(s), message !
tags (annotated)

GIT --@work
Create a repository
git init
initializes a new, empty repository, inside the current directory
git clone https://[email protected]/
stefanprutianu/git-scm-remote.git
clones the remote repository on the local machine, inside a
newly created git-scm-remote folder

GIT --@work
Prepare a commit (stage)
git add <file> | <pattern>
marks the file(s) as belonging to the next commit, i.e. changes
are staged
git reset <file>
removes the file from the staging area

GIT --@work
Commit
git commit -m "Commit message"
records the commit in the repository history
git commit --amend
modifies the last commit by adding the staged changes

GIT --@work
Revert
git checkout -- <file>
the <file> contents in working directory is replaced with the
last committed one
git reset --hard <branch/commit/tag>
discards commits until the one pointed to by the reference
git revert <commit>
reverses the specified commit by creating a new one

GIT --@work
Stash
git stash
saves the working directory state and pushes it on the stashes
stack
git stash apply
gets the most recent stash and applies it to the working
directory

GIT --@work
Share changes
publishing changes
git push <server> <branch>
pushes your changes on the specified branch of the remote
repository
retrieving changes
git fetch <server>
pulls down all the data from the remote repo that you don't
have yet on tracked branches
git pull
does a git pull and merges those on your current branch
git format-patch HEAD --stdout > mypatch.patch

GIT --@work
Branch
git branch <branch name>
creates a new branch starting from your last commit
git checkout -b <branch name>
creates a new branch starting from your last commit and
switches to it
git branch -d <branch name>
deletes the specified branch

GIT --@work
Merge
git merge <branch name>
merges the specified branch into the current one
git rebase <branch name>
rebases the specified branch onto the current one

GIT --@work : merge
using mergeA B E C D master develop master A B E C D develop F
using rebaseA B E C D master develop D' C'

GIT --a branching model
http://nvie.com/posts/a-successful-git-branching-model/master develop hotfix/* feature/* tag 1.0.0 tag 1.1.0 tag 1.1.1 tag 1.5.0

GIT --@work
Status
git log
prints out the commit tree from the current HEAD
git status
shows info like: current branch, working directory status,
staged changes
git stash show
shows the most recent stash
git describe
shows where you are in repository history relatively to the latest
tag, i.e a revision number. Eg: v1.0.0-50-g1f8115b

GIT --@work
Status
git diff <commit>
shows the diff between working directory and specified commit
git branch [-r]
lists either local or remote (-r) branches

GIT --@work
Status

GIT --@work
Release management
git tag v1.0.0 -m "My first release"
creates a "lightweight" tag, i.e. an immovable reference on the
current head
git tag v1.0.0 -a -m "My first release"
creates an "annotated" tag, i.e. an immovable reference on the
current head + info like: tagger, email, date which are stored in
the git database

GIT --@work
Misc
git cherry-pick <commit>
integrates changes in specified commit into the current branch
git bisect
given a start and an end commit reference it will checkout
commits within that range allowing to find a regression
git blame
annotates each line in a file with that last commit to change it

GIT --repository
.gitignore file to express ignore patterns, can be put in
multiple places!
!
git repos smaller than SVN ones, 30x in case of Mozilla !
!
steep learning curve (debatable) !
!
can't checkout part of a repository !
!
oriented towards content rather than files !
!
for transport it supports: HTTP, SSH, GIT protocols !
!
objects are generally added not deleted, reason for git gc

GIT --how to
latest release http://git-scm.com/downloads !
works from CLI !
good GUI clients:
Github for Mac/Win, free ("optimized" for github.com remotes,
but works with others too) !
SourceTree (Mac & Win), free !
Tower (Mac)

(Em)Powered by GIT
https://github.com/
https://bitbucket.org/
https://www.assembla.com/

GIT SCM
integrity
reliable historylocal, flexible, fast
easy branching
non-linear, facilitates collaboration

Thank you!
Questions?
@stefanprutianu