Git & e git beginner workshop

71
Git & EGit beginner Workshop Learn Git with Eclipse EclipseCon France 5 June 2013 Vincent Lalanne Igor Laborie Matthias Sohn

description

Workshop Git for EclipseCon France 2013

Transcript of Git & e git beginner workshop

Page 1: Git & e git beginner workshop

Git & EGit beginner WorkshopLearn Git with Eclipse

EclipseCon France5 June 2013

Vincent LalanneIgor Laborie

Matthias Sohn

Page 2: Git & e git beginner workshop

The team

Igor Laborie Software Architect at AKKAGit enthusiast

Vincent LalanneSoftware Engineer at AKKA

Matthias Sohn Product Owner at SAP

Page 3: Git & e git beginner workshop

The Raspberry Pi

http://www.raspberrypi.org/http://elinux.org/RPi_Hub

Model A ~22 €Model B ~33 €

● ARM processor 700 Mhz● RAM: 512Mb ● HDMI, Composite● Ethernet● 2 USB port● SD Card● 26 Pins

Page 4: Git & e git beginner workshop

Prepare to exercices

RaspberryPi : PiGit / EclipseConOr get EGit-Workshop.zip from an USB stick=> Open index.html with a modern browser

You need an EGit version > v2.2.0=> Install Eclipse Java Juno SR2 if needed.

Exercises are also available at http://ilaborie.github.io/Git--EGit-beginner-workshop

Page 5: Git & e git beginner workshop

Agenda

● Introducing Git● Working locally● Branches● Remotes● Exam

○ => Win a RaspberryPi B !

Page 6: Git & e git beginner workshop

Introducing GitGit, JGit and EGit

Page 7: Git & e git beginner workshop

VCS

A Version Control System● record changes● retrieve a previous version● provide collaborative works

Like SVN, CVS, ClearCase, ...

Page 8: Git & e git beginner workshop

Central VCS Server

Version Database

CVCS

Computer A

File

Checkout

Computer B

File

Checkout

Version 3

Version 1

Version 2

Page 9: Git & e git beginner workshop

DVCSServer Computer

Version Database

Version 3

Version 1

Version 2

Computer B

Version Database

Version 3

Version 1

Version 2

File

Computer A

Version Database

Version 3

Version 1

Version 2

File

Page 10: Git & e git beginner workshop

Git

● easier offline usage● easier to fork and merge (branches)● speed● scalability● a lot of workflow● ...

Git is developer-friendly.Flexibility (with Workflow) is industry-friendly.

Page 11: Git & e git beginner workshop

JGit & EGit

JGit is a (partial) implementation of Git● lightweight,● pure Java library,● modular (OSGi-ready)

EGit is the Eclipse team provider for Git● implemented on top of JGit● Gerrit support● Github support

Page 12: Git & e git beginner workshop

Exercises 1 & 2

1 - Installation & Configuration● http://192.168.42.1/exo1.html● USB Stick: exo1.html● http://ilaborie.github.io/Git--EGit-beginner-

workshop/exo1.html

2 - Create Repositories● http://192.168.42.1/exo2.html● USB Stick: exo2.html● http://ilaborie.github.io/Git--EGit-beginner-

workshop/exo2.html

Page 13: Git & e git beginner workshop

Notes

● Hierarchical configuration level: ○ system

○ user

○ project

● Authentication with Private/Public SSH keys

Page 14: Git & e git beginner workshop

Working LocallyBasic operations

Page 15: Git & e git beginner workshop

Commit

A commit just stores modifications (version) into the repository (local).

Be careful, make significant commits to provide a beautiful history.

Page 16: Git & e git beginner workshop

The Staging Area / Index

● Intermediate zone between the working directory and the repository.

● Useful to prepare commit.● Can be skipped.

Page 17: Git & e git beginner workshop

File status into Git

● A file can beuntracked - not managed by the repositorytracked - managed by the repository

● A tracked file can beunmodified if = last commitmodified if ≠ staging areastaged if ≠ last commit & = staging area*

*

?

Page 18: Git & e git beginner workshop

Add

Working Directory

Staging Area Repository Never

Tracked Files

add**

?

Page 19: Git & e git beginner workshop

Remove

Working Directory

Staging Area RepositoryUntracked Files

remove

Page 20: Git & e git beginner workshop

Move

Working Directory

Staging Area Repository Never

Tracked Files

move

Page 21: Git & e git beginner workshop

Ignore

Working Directory

Staging Area Repository Never

Tracked Files

?ignore

Page 22: Git & e git beginner workshop

Commit

Working Directory

Staging Area Repository Never

Tracked Files

commit

*

Page 23: Git & e git beginner workshop

Exercices 3 & 4

3 - Basic Operations● http://192.168.42.1/exo3.html● USB Stick: exo3.html● http://ilaborie.github.io/Git--EGit-beginner-

workshop/exo3.html

4 - Playing with Diffs (optional)● http://192.168.42.1/exo4.html● USB Stick: exo4.html● http://ilaborie.github.io/Git--EGit-beginner-

workshop/exo4.html

Page 24: Git & e git beginner workshop

Notes

● It's easy to modify the last commit (amend)But Don't modify a shared commit !

● Reset allows you to unstage (and more)

Page 25: Git & e git beginner workshop

BranchesThe DAG

Page 26: Git & e git beginner workshop

Git Objects

sizeblobEclipse Public License

sizeblob<html><head> <title>Index

sizetreesizecommit

blob 5b1d3 README.md

blob 911e7 LICENSE

blob cba0a index.html

tree 92ec2

author Igor

committer Igor

parents ce23a1

First commit of my project

98ca9..92ec2..

sizeblobREADME===

5b1d3..

911e7..

cba0a..

sizecommit...

ce23a1..

Page 27: Git & e git beginner workshop

The Directed Acyclic Graph

c0 c1 c2 c3

c4 c5 c6

c7 c8 c9 c10

c11 c12

Page 28: Git & e git beginner workshop

Branches

c0 c1 c2 c3

c4 c5 c6

c7 c8 c9 c10

c11 c12

HEA

D

mas

ter

feat

ure_

A

feature_B

How many commits in feature A ?

mas

ter

Page 29: Git & e git beginner workshop

Create a new branch: feature_A

c0 c1 c2 c3

master

Page 30: Git & e git beginner workshop

Create a new branch: feature_A

c0 c1 c2 c3

master

feat

ure_

A

Page 31: Git & e git beginner workshop

Create a new branch: feature_A

c0 c1 c2 c3

master

feat

ure_

A

Page 32: Git & e git beginner workshop

Implementing the feature A

c0 c1 c2 c3

master

feat

ure_

A

Page 33: Git & e git beginner workshop

Implementing the feature A

c0 c1 c2 c3

master

c4fe

atur

e_A

Page 34: Git & e git beginner workshop

Implementing the feature A

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 35: Git & e git beginner workshop

Checkout to master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 36: Git & e git beginner workshop

Checkout to master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 37: Git & e git beginner workshop

Working on master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 38: Git & e git beginner workshop

Working on master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

master

Page 39: Git & e git beginner workshop

Working on master

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 40: Git & e git beginner workshop

Create a new branch: feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 41: Git & e git beginner workshop

Create a new branch: feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

feature_B

Page 42: Git & e git beginner workshop

Implementing the feature B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

feature_B

Page 43: Git & e git beginner workshop

Implementing the feature B

c8feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 44: Git & e git beginner workshop

Implementing the feature B

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 45: Git & e git beginner workshop

Step back to master

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 46: Git & e git beginner workshop

Step back to master

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 47: Git & e git beginner workshop

Let's merge master with feature_A

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 48: Git & e git beginner workshop

Let's merge master with feature_A

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Page 49: Git & e git beginner workshop

Go to feature_B

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Page 50: Git & e git beginner workshop

Go to feature_B

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Page 51: Git & e git beginner workshop

Let's rebase on master

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Page 52: Git & e git beginner workshop

Let's rebase on master

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

c8'

Page 53: Git & e git beginner workshop

Let's rebase on master

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

c8' c9'

Page 54: Git & e git beginner workshop

Let's rebase on master

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

c8' c9'

Page 55: Git & e git beginner workshop

Let's rebase on master

feature_B

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

c8' c9'

c8 c9

Page 56: Git & e git beginner workshop

Merge vs Rebase

feature_B

c0 c1 c2 c3

c4 c5

feat

ure_

A

c6

c10

mas

ter

c7

c8' c9'

c9

feature_B

c8

c0 c1 c2 c3

c4 c5

feat

ure_

A

c6

c10

mas

ter

c7 c11

Page 57: Git & e git beginner workshop

Exercices 5 & 6

5 - Branches Workflow● http://192.168.42.1/exo5.html● USB Stick: exo5.html● http://ilaborie.github.io/Git--EGit-beginner-

workshop/exo5.html

6 - Handle Conflicts (Optional)● http://192.168.42.1/exo6.html● USB Stick: exo6.html● http://ilaborie.github.io/Git--EGit-beginner-

workshop/exo6.html

Page 58: Git & e git beginner workshop

Notes

● Tag is a reference on a commit

● SHA-1 allow integrity check (fsck)

● Git rarely deletes data, reflog could save your life

Page 59: Git & e git beginner workshop

RemotesSharing

Page 60: Git & e git beginner workshop

Remotes

A remote repositories is defined by● an alias,● an URL

ssh://http://https://file://

git://

Page 61: Git & e git beginner workshop

Initially

Remote

mas

ter

c0

Local

Page 62: Git & e git beginner workshop

Clone

Remote Local

mas

ter

c0

ori

gin

/mas

ter

c0

master

Page 63: Git & e git beginner workshop

A Local Commit

Remote Local

mas

ter

c0

ori

gin

/mas

ter

c0

master

c1

Page 64: Git & e git beginner workshop

A Remote Commit

Remote Localm

aste

r

c0

ori

gin

/mas

ter

c0

master

c1c2

Page 65: Git & e git beginner workshop

Fetch

mas

ter

Remote

c0

ori

gin

/mas

ter

Local

c0

master

c1

c2

c2

Page 66: Git & e git beginner workshop

Pull

mas

ter

Remote

c0

Localm

aster

c2 c3

ori

gin

/mas

ter

c0

c1

c2

Page 67: Git & e git beginner workshop

Push

mas

ter

Remote

c0

Localm

aster

c3

ori

gin

/mas

ter

c0

c1

c2

c3

c1

c2

Page 69: Git & e git beginner workshop

Notes

● Blame show commit details for each line of a file (Annotation)

● Branch tracking

● Upstream

Page 70: Git & e git beginner workshop

Examhttp://git-quizz.herokuapp.com/

Page 71: Git & e git beginner workshop

ThanksQuestion(s)