git the fast version control system

58

Click here to load reader

Upload: amsterdamscala

Post on 16-Apr-2017

2.449 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Git the fast version control system

GitThe fast version control system

Jeroen Rosenberg [email protected]

m

Page 2: Git the fast version control system

Git - the fast version control system

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

Page 3: Git the fast version control system

Git - the fast version control system

Version controlShort introduction

Page 4: Git the fast version control system

Git - the fast version control system

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

Page 5: Git the fast version control system

Git - the fast version control system

Version control (2)

Benefits

Page 6: Git the fast version control system

Git - the fast version control system

Version control (2)

Benefits Allows a team to share code

Page 7: Git the fast version control system

Git - the fast version control system

Version control (2)

Benefits Allows a team to share code Maintains separate “production”

versions of code that are always deployable

Page 8: Git the fast version control system

Git - the fast version control system

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

Page 9: Git the fast version control system

Git - the fast version control system

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

Page 10: Git the fast version control system

Git - the fast version control system

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

Page 11: Git the fast version control system

Git - the fast version control system

GlossarySome commonly used terms explained before moving

on

Page 12: Git the fast version control system

Git - the fast version control system

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 under version control

Trunk the unique line of development that is not a branch

Update to retrieve and integrate changes in the repository since the update.

Working copy your local copies of the files under version control you want to edit

Page 13: Git the fast version control system

Git - the fast version control system

Version control systems

Page 14: Git the fast version control system

Git - the fast version control system

Very limited and inflexible

Concurrent Versions System (CVS)

Page 15: Git the fast version control system

Git - the fast version control system

Very limited and inflexible

Concurrent Versions System (CVS)

Fills most of the holes found in CVS, but added nothing to its development model

Subversion (SVN)

Page 16: Git the fast version control system

Git - the fast version control system

Very limited and inflexible

Concurrent Versions System (CVS)

Fills most of the holes found in CVS, but added nothing to its development model

Subversion (SVN)

More feature rich and functional

Git

Page 17: Git the fast version control system

Git - the fast version control system

Comparison with SVN

Subversion Git

Page 18: Git the fast version control system

Git - the fast version control system

Comparison with SVN

Subversion Centralized

Git Distributed

Page 19: Git the fast version control system

Git - the fast version control system

Comparison with SVN

Subversion Centralized Branching can be a pain and

is used sparingly

Git Distributed Branching is very easy and

is a core concept

Page 20: Git the fast version control system

Git - the fast version control system

Comparison with SVN

Subversion Centralized Branching can be a pain and

is used sparingly Conflicts frequently occur

and renaming is not handled well

Git Distributed Branching is very easy and

is a core concept Conflicts occur less frequent,

renaming is properly handled

Page 21: Git the fast version control system

Git - the fast version control system

Comparison with SVN

Subversion Centralized Branching can be a pain and

is used sparingly Conflicts frequently occur

and renaming is not handled well

Can be slow due to network latency

Git Distributed Branching is very easy and

is a core concept Conflicts occur less frequent,

renaming is properly handled

Very fast since less operations involve network latency

Page 22: Git the fast version control system

Git - the fast version control system

Comparison with SVN

Subversion Centralized Branching can be a pain and

is used sparingly Conflicts frequently occur

and renaming is not handled well

Can be slow due to network latency

Can consume quite some disk space

Git Distributed Branching is very easy and

is a core concept Conflicts occur less frequent,

renaming is properly handled

Very fast since less operations involve network latency

Consumes 30 times less disk space

Page 23: Git the fast version control system

Git - the fast version control system

Distributed version control

The new generation of version control

Page 24: Git the fast version control system

Git - the fast version control system

A basic, centralized version control systemUsers commit changes to the central repository and a new version is born to be checked out by other users

Page 25: Git the fast version control system

Git - the fast version control system

A distributed version control systemEach 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

Page 26: Git the fast version control system

Git - the fast version control system

Git usageBasic operations

Page 27: Git the fast version control system

Git - the fast version control system

Tracking a project..

SVN Git$ svn checkout url

$ git clone url

Page 28: Git the fast version control system

Git - the fast version control system

Tracking a project..

SVN Git$ svn checkout url

$ git clone url

Mirror the central server

Anything the main repository can do, you can do!

Page 29: Git the fast version control system

Git - the fast version control system

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?”

Page 30: Git the fast version control system

Git - the fast version control system

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”

Page 31: Git the fast version control system

Git - the fast version control system

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

pathPretty straightforwarded, huh?

Page 32: Git the fast version control system

Git - the fast version control system

Advanced committing…

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

pathWhat if you screw up?# re-edit the metadata and update the tree$ git commit --amend

or

# toss your latest commit away without changing the working tree$ git reset HEAD^

Page 33: Git the fast version control system

Git - the fast version control system

Solving conflictsInstant merging

Page 34: Git the fast version control system

Git - the fast version control system

Closer look at pulling..

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

Page 35: Git the fast version control system

Git - the fast version control system

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

Page 36: Git the fast version control system

Git - the fast version control system

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

Page 37: Git the fast version control system

Git - the fast version control system

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 fileAutomatic merge failed; fix conflicts and then commit the result.

Uh oh…. now what?

Page 38: Git the fast version control system

Git - the fast version control system

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

Page 39: Git the fast version control system

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

Page 40: Git the fast version control system

Git - the fast version control system

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

Page 41: Git the fast version control system

Git - the fast version control system

BranchingA core concept

Page 42: Git the fast version control system

Git - the fast version control system

Creating a branch..

SVN Git$ svn copy url_of_trunk url_of_branch

$ svn switch url_of_branch

$ git branch name_of_branch

$ git checkout name_of_branch

Page 43: Git the fast version control system

Git - the fast version control system

Creating a branch..

SVN Git$ svn copy url_of_trunk url_of_branch

$ svn switch url_of_branch

$ git branch name_of_branch

$ git checkout name_of_branch

Or create and switch to a branch based on another branch

$ git checkout –b new_branch other_branch

Page 44: Git the fast version control system

Git - the fast version control system

Some common scenarios…Why would I require branching?

Page 45: Git the fast version control system

Git - the fast version control system

Scenario 1 – Interrupted workflowYou’re finished with part 1 of a new feature but you can’t continue with part 2 before part 1 is released and tested

Page 46: Git the fast version control system

Git - the fast version control system

Scenario 1 – Interrupted workflowYou’re finished with part 1 of a new feature but you can’t continue with part 2 before part 1 is released and tested

Page 47: Git the fast version control system

Git - the fast version control system

Scenario 2 – Quick fixesWhile you’re busy implementing some feature suddenly you’re being told to drop everything and fix a newly discovered bug

Page 48: Git the fast version control system

Git - the fast version control system

Scenario 2 – Quick fixesWhile you’re busy implementing some feature suddenly you’re being told to drop everything and fix a newly discovered bug

Page 49: Git the fast version control system

Git - the fast version control system

Git usage overview

Just to summarize…

Page 50: Git the fast version control system

Git - the fast version control system

Git command sequence

Source: http://git.or.cz

Page 51: Git the fast version control system

Git - the fast version control system

ToolingStuck at ‘Ye Olde Terminal’? Not necessarily…

Page 52: Git the fast version control system

Git - the fast version control system

Git UI front-ends

Page 53: Git the fast version control system

Git - the fast version control system

OpenInGitGuiFinder extension

Page 54: Git the fast version control system

Git - the fast version control system

OpenInGitGuiFinder extension

TortoiseGit

Git Extensions

Windows Explorer extensions

Page 55: Git the fast version control system

Git - the fast version control system

OpenInGitGuiFinder extension

TortoiseGit

Git Extensions

Windows Explorer extensions

JGit / EGitEclipse integration

Page 56: Git the fast version control system

Git - the fast version control system

ConclusionWhy switch to Git?

Page 57: Git the fast version control system

Git - the fast version control system

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

Page 58: Git the fast version control system

Git - the fast version control system

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/