25
Introduction to Git Uri Goldstein

Intro to Git and GitHub

Embed Size (px)

Citation preview

Introduction to Git

Uri Goldstein

What is Git?

• A Version Control System like SVN - ONLY BETTER.

• Everything is faster and easier:– Committing.– Reverting.– Branching.– Merging.

• Work disconnected = Offline.

What is GitHub?

• A web-based git hosting service.• Like Assembla, only better. • Uses a simple workflow = GitHub Flow.• Extremely popular.• A community of devs sharing code.

But…

• Git is a Swiss Army Knife.• Once you master it,

it’ll make your life easier.

LIFECYCLE OF A CHANGE

Subversion

SVN Server

TCMW Repository

Uri’s Machine

TCMWLocal Copy

Lior’s Machine

TCMWLocal Copy

Git – Everyone Gets a Repo

Git Server

TCMW Repository

Uri’s Machine

TCMWWorking

Copy

Lior’s Machine

TCMWWorking

Copy

TCMW Repository

TCMW Repository

“Origin”

GitHubUri’s Machine

Lifecycle of a Change

Staging Area

Local GitRepository

Remote GitRepository

Commit PushC:\dev\MyClass.cs

Stage

Demo

Lifecycle of a Change – Cont’d

GitHubLior’s Machine

C:\dev\MyClass.cs

Local GitRepository

Remote GitRepository

Merge Pull

BRANCHES

Subversion

• Creating branches takes time.• Commits are big.• SVN stores diffs in repo. • Merging is a pain

Subversion

TrunkUri makes changeson his machine

Lior makes changeson his machine

Conflict

Git

• Creating branches is a snap.• Commits are small and frequent.• Git stores full files in repo.• Merging is a joy much less painful.

MasterLior’s Feature

Git

Uri’s Feature

Branch

Pull

Push

Branch

Pull

Push

Pull

Pull

Master

Branch

Push

Lior’s Feature

Git

Uri’s Feature

Uri’s Bug Fix

Branch

Pull

Push

Branch

Pull

Push

Pull

Pull

Demo

GITHUB AND GITHUB FLOW

GitHub

• Huge online community for open-source projects = Public.

• Huge online service for commercial start-ups and enterprises = PRIVATE.

• Runs Git Flow.

GitHub Flow

GitHub Flow

• ‘master’ branch is always stable.• Devs use ‘feature’* branches.• Feature branches pull from master freely.• Feature branches merge back to master via

Pull Request = PR.• Pull Request reviewed by peer + auto tests. ‘master’ branch is always stable.

A day in the life 1/2

• Brew a hot cup of coffee.• Pull latest from origin master.• Need to work on new feature • Branch = create new feature branch.• Code and commit in small increments.

• Lunch!

A day in the life 2/2

• Brew a hot cup of coffee.• Pull latest from origin master.• Resolve tiny conflicts easily.• Verify quality with unit/integ. tests.• Submit Pull Request (PR) for review.• Nag reviewers to review.• PR accepted? Verify master green on build server

• Celebrate the day with a drink.

Demo