You are on page 1of 58

lickoC

c tpurea
ntado
n u
p
d
e

Git

The fast version control system

Jeroen Rosenberg
jeroen.rosenberg@gmail.co
m
Table of contents

Short introduction to version control


Version control systems
Comparison with subversion
Distributed version control
Git usage
Basic operations
Solving conflicts
Branching as a core concept
Tooling
Conclusion
Git - the fast version control
Version control

Short introduction

Git - the fast version control


Version control (1)

The management of changes to


documents, programs, and other
information stored as computer files
A system that maintains versions of files
at progressive stages of development.
Every file
Has a full history of changes
Can be restored to any version
A communication tool, like email, but
with code rather than human
conversation

Git - the fast version control


Version control (2)

Benefits

Git - the fast version control


Version control (2)

Benefits
Allows a team to share code

Git - the fast version control


Version control (2)

Benefits
Allows a team to share code
Maintains separate “production” versions
of code that are always deployable

Git - the fast version control


Version control (2)

Benefits
Allows a team to share code
Maintains separate “production” versions
of code that are always deployable
Allows simultaneous development of
different features on the same codebase

Git - the fast version control


Version control (2)

Benefits
Allows a team to share code
Maintains separate “production” versions
of code that are always deployable
Allows simultaneous development of
different features on the same codebase
Keeps track of all old versions of files

Git - the fast version control


Version control (2)

Benefits
Allows a team to share code
Maintains separate “production” versions
of code that are always deployable
Allows simultaneous development of
different features on the same codebase
Keeps track of all old versions of files
Prevents work being overwritten

Git - the fast version control


Glossary

Some commonly used terms explained before moving


on

Git - the fast version control


Key terms in version
control

Branch a copy of a set of files under


version control which may be developed
at different speeds or in different ways
Checkout to copy the latest version of
(a file in) the repository to your working
copy
Commit to copy (a file in) your working
copy back into the repository as a new
version
Merge to combine multiple changes
made to different working copies of the
same files in the repository
Repository a (shared) database with
the complete revision history of all files
Git - the fast version control under version control
Version control
systems

Git - the fast version control


Click icon to add picture Concurrent Versions
System (CVS)
Very limited and inflexible

Click icon to add picture

Click icon to add picture


Git - the fast version control
Click icon to add picture Concurrent Versions
System (CVS)
Very limited and inflexible

Click icon to add picture Subversion (SVN)

Fills most of the holes found in


CVS, but added nothing to its
development model

Click icon to add picture


Git - the fast version control
Click icon to add picture Concurrent Versions
System (CVS)
Very limited and inflexible

Click icon to add picture Subversion (SVN)

Fills most of the holes found in


CVS, but added nothing to its
development model

Git

More feature rich and


functional

Click icon to add picture


Click icon to add picture
Git - the fast version control
Comparison with SVN

Subversion Git

Git - the fast version control


Comparison with SVN

Subversion Git

Centralized Distributed

Git - the fast version control


Comparison with SVN

Subversion Git

Centralized Distributed
Branching can be a pain and Branching is very easy and is
is used sparingly a core concept

Git - the fast version control


Comparison with SVN

Subversion Git

Centralized Distributed
Branching can be a pain and Branching is very easy and is
is used sparingly a core concept
Conflicts frequently occur and Conflicts occur less frequent,
renaming is not handled well renaming is properly handled

Git - the fast version control


Comparison with SVN

Subversion Git

Centralized Distributed
Branching can be a pain and Branching is very easy and is
is used sparingly a core concept
Conflicts frequently occur and Conflicts occur less frequent,
renaming is not handled well renaming is properly handled
Can be slow due to network Very fast since less operations
latency involve network latency

Git - the fast version control


Comparison with SVN

Subversion Git

Centralized Distributed
Branching can be a pain and Branching is very easy and is
is used sparingly a core concept
Conflicts frequently occur and Conflicts occur less frequent,
renaming is not handled well renaming is properly handled
Can be slow due to network Very fast since less operations
latency involve network latency
Can consume quite some disk Consumes 30 times less disk
space space

Git - the fast version control


Distributed
version control
The new generation of version control

Git - the fast version control


Click icon to add picture

A basic, centralized version control


system
Users commit changes to the central repository and a new
version is born to be checked out by other users

Git - the fast version control


Click icon to add picture

A distributed version control system

Each user has a full local copy of the repository. Users


commit changes and when they want to share it, the push it
to the shared repository

Git - the fast version control


Git usage

Basic operations

Git - the fast version control


Tracking a project..

SVN Git
$ svn checkout url $ git clone url

Git - the fast version control


Tracking a project..

SVN Git
$ svn checkout url $ git clone url

Mirror the central server

Anything the main repository can do, you


Git - the fast version control can do!
Tracking a project..

SVN Git
$ svn checkout url $ git clone url

My project is tiny - git is overkill


“Why would I carry a Swiss knife when I
only want to open cans?”

Git - the fast version control


Tracking a project..

SVN Git
$ svn checkout url $ git clone url

Tiny projects should be scalable too!


“You wouldn’t use Roman digits just
because you perform calculations with
small numbers, now would you?”

Tiny projects may grow beyond your


expectations
“One day you’ll desperately need that
hex wrench and you’re stuck with your
plain can-opener”
Git - the fast version control
Tracking a project..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
$ svn rm file $ git rm file
$ svn mv file $ git mv file
$ svn commit $ git commit –a
$ svn revert path $ git checkout path

Pretty straightforwarded, huh?

Git - the fast version control


Advanced committing…

SVN Git
… …
$ svn mv file $ git mv file
$ svn commit $ git commit –a
$ svn revert path $ git checkout path

What if you screw up?


# re-edit the metadata and update
the tree
$ git commit --amend

or

# toss your latest commit away


Git - the fast version control without changing the working tree
$ git reset HEAD^
Solving conflicts

Instant merging

Git - the fast version control


Closer look at pulling..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
… …

Git - the fast version control


Auto-merging..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
… …

What actually happens…

# Fetch latest changes from origin


$ git fetch

# Merge fetched changes into


current branch
$ git merge refs/heads/master
Git - the fast version control
Auto-merging..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
… …

What actually happens…

Recursive merge strategy – create a


merged reference tree of common
ancestors for three-way merge

§ fewer merge conflicts


§ can detect and handle renames
Git - the fast version control
Resolving conflicts..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
… …

Suppose Jeff and Dan both made


changes to the same line in file…

CONFLICT (content): Merge conflict in file


Automatic merge failed; fix conflicts and
then commit the result.

Uh oh…. now what?


Git - the fast version control
Resolving conflicts..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
… …

Well, just merge manually…

# run your favourite file merge


application
$ git mergetool –t opendiff

Git - the fast version control


Git - the fast version control source: http://gitguru.com
Resolving conflicts..

SVN Git
$ svn checkout url $ git clone url
$ svn update $ git pull
$ svn add file $ git add file
… …

…and commit!

# commit to resolve the conflict


$ git commit

Git - the fast version control


Branching

A core concept

Git - the fast version control


Creating a branch..

SVN Git
$ svn copy $ git branch
url_of_trunk name_of_branch
url_of_branch

$ svn switch $ git checkout


url_of_branch name_of_branch

Git - the fast version control


Creating a branch..

SVN Git
$ svn copy $ git branch
url_of_trunk name_of_branch
url_of_branch

$ svn switch $ git checkout


url_of_branch name_of_branch

Or create and switch to a branch


based on another branch

$ git checkout –b new_branch


other_branch

Git - the fast version control


Click icon to add picture

Why would I require branching?

Some common scenarios…

Git - the fast version control


Scenario 1 – Interrupted workflow

You’re finished with part 1 of a new feature but


you can’t continue with part 2 before part 1 is
released and tested

Git - the fast version control


Scenario 1 – Interrupted workflow

You’re finished with part 1 of a new feature but


you can’t continue with part 2 before part 1 is
released and tested

Git - the fast version control


Scenario 2 – Quick fixes

While you’re busy implementing some feature


suddenly you’re being told to drop everything and
fix a newly discovered bug

Git - the fast version control


Scenario 2 – Quick fixes

While you’re busy implementing some feature


suddenly you’re being told to drop everything and
fix a newly discovered bug

Git - the fast version control


Git usage
overview
Just to summarize…

Git - the fast version control


Git command sequence

Source: http://git.or.cz

Git - the fast version control


Tooling

Stuck at ‘Ye Olde Terminal’? Not necessarily…

Git - the fast version control


Git UI front-ends

Git - the fast version control


Click icon to add picture Finder extension

§ OpenInGitGui

Click icon to add picture

Click icon to add picture


Git - the fast version control
Click icon to add picture Finder extension

§ OpenInGitGui

Click icon to add picture Windows Explorer


extensions
§ TortoiseGit
§ Git Extensions

Click icon to add picture


Git - the fast version control
Click icon to add picture Finder extension

§ OpenInGitGui

Click icon to add picture Windows Explorer


extensions
§ TortoiseGit
§ Git Extensions

Eclipse integration

§ JGit / EGit

Click icon to add picture


Git - the fast version control
Conclusion

Why switch to Git?

Git - the fast version control


Reasons to switch to Git

Endless, easy, non-file-system-based,


local branches

Enhanced merging strategy

Performance

Advanced features enable better


workflow
Stashing temporary work
Collaboration before public commits

Git - the fast version control


Closing and Q&A

References
Git: http://git-scm.com/download
Git Docs: http://git-scm.com/documentation
GitX: http://gitx.frim.nl/
TortoiseGit: http://code.google.com/p/tortoisegit/
Git Extensions:
http://sourceforge.net/projects/gitextensions/
JGit / EGit: http://www.eclipse.org/egit/

Git - the fast version control

You might also like