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

Git & EGit beginner Workshop.pdf

Embed Size (px)

Citation preview

Page 1: Git & EGit beginner Workshop.pdf

Git & EGit beginner WorkshopLearn Git with Eclipse

EclipseCon France5 June 2013

Vincent LalanneIgor Laborie

Matthias Sohn

Page 2: Git & EGit beginner Workshop.pdf

The team

Igor Laborie Software Architect at AKKAGit enthusiast

Vincent LalanneSoftware Engineer at AKKA

Matthias Sohn Product Owner at SAP

Page 3: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

Agenda

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

○ => Win a RaspberryPi B !

Page 6: Git & EGit beginner Workshop.pdf

Introducing GitGit, JGit and EGit

Page 7: Git & EGit beginner Workshop.pdf

VCS

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

Like SVN, CVS, ClearCase, ...

Page 8: Git & EGit beginner Workshop.pdf

Central VCS Server

Version Database

CVCS

Computer A

File

Checkout

Computer B

File

Checkout

Version 3

Version 1

Version 2

Page 9: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

Notes

● Hierarchical configuration level: ○ system

○ user

○ project

● Authentication with Private/Public SSH keys

Page 14: Git & EGit beginner Workshop.pdf

Working LocallyBasic operations

Page 15: Git & EGit beginner Workshop.pdf

Commit

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

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

Page 16: Git & EGit beginner Workshop.pdf

The Staging Area / Index

● Intermediate zone between the working directory and the repository.

● Useful to prepare commit.● Can be skipped.

Page 17: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

Add

Working Directory

Staging Area Repository Never

Tracked Files

add**

?

Page 19: Git & EGit beginner Workshop.pdf

Remove

Working Directory

Staging Area RepositoryUntracked Files

remove

Page 20: Git & EGit beginner Workshop.pdf

Move

Working Directory

Staging Area Repository Never

Tracked Files

move

Page 21: Git & EGit beginner Workshop.pdf

Ignore

Working Directory

Staging Area Repository Never

Tracked Files

?ignore

Page 22: Git & EGit beginner Workshop.pdf

Commit

Working Directory

Staging Area Repository Never

Tracked Files

commit

*

Page 23: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

BranchesThe DAG

Page 26: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

The Directed Acyclic Graph

c0 c1 c2 c3

c4 c5 c6

c7 c8 c9 c10

c11 c12

Page 28: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

Create a new branch: feature_A

c0 c1 c2 c3

master

Page 30: Git & EGit beginner Workshop.pdf

Create a new branch: feature_A

c0 c1 c2 c3

master

feat

ure_

A

Page 31: Git & EGit beginner Workshop.pdf

Create a new branch: feature_A

c0 c1 c2 c3

master

feat

ure_

A

Page 32: Git & EGit beginner Workshop.pdf

Implementing the feature A

c0 c1 c2 c3

master

feat

ure_

A

Page 33: Git & EGit beginner Workshop.pdf

Implementing the feature A

c0 c1 c2 c3

master

c4fe

atur

e_A

Page 34: Git & EGit beginner Workshop.pdf

Implementing the feature A

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 35: Git & EGit beginner Workshop.pdf

Checkout to master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 36: Git & EGit beginner Workshop.pdf

Checkout to master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 37: Git & EGit beginner Workshop.pdf

Working on master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Page 38: Git & EGit beginner Workshop.pdf

Working on master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

master

Page 39: Git & EGit beginner Workshop.pdf

Working on master

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 40: Git & EGit beginner Workshop.pdf

Create a new branch: feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 41: Git & EGit beginner Workshop.pdf

Create a new branch: feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

feature_B

Page 42: Git & EGit beginner Workshop.pdf

Implementing the feature B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

feature_B

Page 43: Git & EGit beginner Workshop.pdf

Implementing the feature B

c8feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 44: Git & EGit beginner Workshop.pdf

Implementing the feature B

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 45: Git & EGit beginner Workshop.pdf

Step back to master

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 46: Git & EGit beginner Workshop.pdf

Step back to master

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Page 47: Git & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

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 & EGit beginner Workshop.pdf

RemotesSharing

Page 60: Git & EGit beginner Workshop.pdf

Remotes

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

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

git://

Page 61: Git & EGit beginner Workshop.pdf

Initially

Remote

mas

ter

c0

Local

Page 62: Git & EGit beginner Workshop.pdf

Clone

Remote Local

mas

ter

c0

ori

gin

/mas

ter

c0

master

Page 63: Git & EGit beginner Workshop.pdf

A Local Commit

Remote Local

mas

ter

c0

ori

gin

/mas

ter

c0

master

c1

Page 64: Git & EGit beginner Workshop.pdf

A Remote Commit

Remote Localm

aste

r

c0

ori

gin

/mas

ter

c0

master

c1c2

Page 65: Git & EGit beginner Workshop.pdf

Fetch

mas

ter

Remote

c0

ori

gin

/mas

ter

Local

c0

master

c1

c2

c2

Page 66: Git & EGit beginner Workshop.pdf

Pull

mas

ter

Remote

c0

Localm

aster

c2 c3

ori

gin

/mas

ter

c0

c1

c2

Page 67: Git & EGit beginner Workshop.pdf

Push

mas

ter

Remote

c0

Localm

aster

c3

ori

gin

/mas

ter

c0

c1

c2

c3

c1

c2

Page 69: Git & EGit beginner Workshop.pdf

Notes

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

● Branch tracking

● Upstream

Page 70: Git & EGit beginner Workshop.pdf

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

Page 71: Git & EGit beginner Workshop.pdf

ThanksQuestion(s)