Git & e git beginner workshop

Post on 19-Jan-2015

462 views 1 download

Tags:

description

Workshop Git for EclipseCon France 2013

Transcript of Git & e git beginner workshop

Git & EGit beginner WorkshopLearn Git with Eclipse

EclipseCon France5 June 2013

Vincent LalanneIgor Laborie

Matthias Sohn

The team

Igor Laborie Software Architect at AKKAGit enthusiast

Vincent LalanneSoftware Engineer at AKKA

Matthias Sohn Product Owner at SAP

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

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

Agenda

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

○ => Win a RaspberryPi B !

Introducing GitGit, JGit and EGit

VCS

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

Like SVN, CVS, ClearCase, ...

Central VCS Server

Version Database

CVCS

Computer A

File

Checkout

Computer B

File

Checkout

Version 3

Version 1

Version 2

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

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.

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

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

Notes

● Hierarchical configuration level: ○ system

○ user

○ project

● Authentication with Private/Public SSH keys

Working LocallyBasic operations

Commit

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

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

The Staging Area / Index

● Intermediate zone between the working directory and the repository.

● Useful to prepare commit.● Can be skipped.

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*

*

?

Add

Working Directory

Staging Area Repository Never

Tracked Files

add**

?

Remove

Working Directory

Staging Area RepositoryUntracked Files

remove

Move

Working Directory

Staging Area Repository Never

Tracked Files

move

Ignore

Working Directory

Staging Area Repository Never

Tracked Files

?ignore

Commit

Working Directory

Staging Area Repository Never

Tracked Files

commit

*

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

Notes

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

● Reset allows you to unstage (and more)

BranchesThe DAG

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..

The Directed Acyclic Graph

c0 c1 c2 c3

c4 c5 c6

c7 c8 c9 c10

c11 c12

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

Create a new branch: feature_A

c0 c1 c2 c3

master

Create a new branch: feature_A

c0 c1 c2 c3

master

feat

ure_

A

Create a new branch: feature_A

c0 c1 c2 c3

master

feat

ure_

A

Implementing the feature A

c0 c1 c2 c3

master

feat

ure_

A

Implementing the feature A

c0 c1 c2 c3

master

c4fe

atur

e_A

Implementing the feature A

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Checkout to master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Checkout to master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Working on master

c0 c1 c2 c3

master

c4 c5

feat

ure_

A

Working on master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

master

Working on master

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Create a new branch: feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Create a new branch: feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

feature_B

Implementing the feature B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

feature_B

Implementing the feature B

c8feature_B

c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Implementing the feature B

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Step back to master

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Step back to master

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

Let's merge master with feature_A

c9

feature_B

c8c7

master

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

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

Go to feature_B

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Go to feature_B

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Let's rebase on master

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

Let's rebase on master

c9

feature_B

c8

c0 c1 c2 c3

c4 c5fe

atur

e_A

c6

c10

mas

ter

c7

c8'

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'

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'

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

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

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

Notes

● Tag is a reference on a commit

● SHA-1 allow integrity check (fsck)

● Git rarely deletes data, reflog could save your life

RemotesSharing

Remotes

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

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

git://

Initially

Remote

mas

ter

c0

Local

Clone

Remote Local

mas

ter

c0

ori

gin

/mas

ter

c0

master

A Local Commit

Remote Local

mas

ter

c0

ori

gin

/mas

ter

c0

master

c1

A Remote Commit

Remote Localm

aste

r

c0

ori

gin

/mas

ter

c0

master

c1c2

Fetch

mas

ter

Remote

c0

ori

gin

/mas

ter

Local

c0

master

c1

c2

c2

Pull

mas

ter

Remote

c0

Localm

aster

c2 c3

ori

gin

/mas

ter

c0

c1

c2

Push

mas

ter

Remote

c0

Localm

aster

c3

ori

gin

/mas

ter

c0

c1

c2

c3

c1

c2

Notes

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

● Branch tracking

● Upstream

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

ThanksQuestion(s)