patterns & practices symposium 2013 introducing git version control into your team mark groves...

137
patterns & practices Symposium 2013 Introducing Git version control into your team Mark Groves [email protected] @mgroves84

Upload: dylan-barnett

Post on 23-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

patterns & practices Symposium 2013

Introducing Git version control into your team

Mark [email protected]

@mgroves84

Symposium 2013

Agenda Introduction What is Git? Git 101 Enabling Team Development Short vs. Long Lived Branches Deploying with Git Your Org uses TFS? Tools/Resources

WHO AM I?

Mark GrovesPrincipal Program ManagerDeveloper Division

History

History

Created by Linus Torvalds for work on the Linux kernel ~2005

History

Created by Linus Torvalds for work on the Linux kernel ~2005Some of the companies that use git:

What is Git?

Git is a

DistributedVersion Control System

OR

Git is a

DirectoryContent Management System

Git is a

history storage system

Tree

Git is a

content trackerStupid

How ever you think about it…

How ever you think about it…

Git is SUPER cool

Distributed

Everyone has the complete history

Distributed

Everything is done offline

…except push/pull

Everyone has the complete history

Distributed

Everything is done offlineEveryone has the complete history

No central authority

…except by convention

Distributed

Everything is done offlineEveryone has the complete history

No central authorityChanges can be shared without a server

Centralized VC vs. Distributed VC

Central ServerRemote Server

Branching

BranchingForget what you know from Central VC(…TFS, SVN, Perforce...)

BranchingForget what you know from Central VCGit branch is “Sticky Note” on a graph node

BranchingForget what you know from Central VCGit branch is “Sticky Note” on a graph nodeAll branch work takes place within the same folder within your file system.

BranchingForget what you know from Central VCGit branch is “Sticky Note” on the graphAll branch work takes place within the same folder within your file system. When you switch branches you are moving the “Sticky Note”

InitializationC:\> mkdir CoolProjectC:\> cd CoolProjectC:\CoolProject > git initInitialized empty Git repository in C:/CoolProject/.gitC:\CoolProject > notepad README.txtC:\CoolProject > git add .C:\CoolProject > git commit -m 'my first commit'[master (root-commit) 7106a52] my first commit 1 file changed, 1 insertion(+) create mode 100644 README.txt

Branches Illustrated

master

A

> git commit –m ‘my first commit’

Branches Illustrated

master

> git commit (x2)

A B C

Branches Illustrated

bug123

master

> git checkout –b bug123

A B C

Branches Illustrated

master

> git commit (x2)

A B C

D Ebug12

3

Branches Illustrated

master

> git checkout master

A B C

D Ebug12

3

Branches Illustrated

bug123

master

> git merge bug123

A B C D E

Branches Illustrated

master

> git branch -d bug123

A B C D E

Branches Illustrated

master

A B C D E

F Gbug45

6

Branches Illustrated

master

A B C D E

F Gbug45

6

> git checkout master

Branches Illustrated

master

A B C D E

F G

> git merge bug456

H

bug456

Branches Illustrated

master

A B C D E

F G

> git branch -d bug456

H

Branches Illustrated

master

A B C D E

F Gbug45

6

Branches Illustrated

master

A B C D E

> git rebase master

F’G’ bug45

6

Branches Illustrated

master

A B C D E

> git checkout master> git merge bug456

F’G’ bug45

6

Branching Review

Branching ReviewQuick and Easy to create ‘Feature’ Branches

Branching Review

Local branches are very powerfulQuick and Easy to create ‘Feature’ Branches

Branching Review

Local branches are very powerfulQuick and Easy to create ‘Feature’ Branches

Rebase is not scary

Software is a Team Sport

Sharing commits

My Local Repo

Tom’s Repo

Tracey’s Repo

Matt’s Repo

A B C

A B C A B C

A B C

Adding a Remote

Sharing commits

My Local Repo

Tom’s Repo

Tracey’s Repo

Matt’s Repo

A B C

A B C A B C

A B C

Remote Repo

A B C

D

D

D

D

D

Setting up a Remote

Setting up a Remote

Adding a remote to an existing local repoC:\CoolProject > git remote add origin

https://git01.codeplex.com/coolprojectC:\CoolProject > git remote -vorigin https://git01.codeplex.com/coolproject (fetch)origin https://git01.codeplex.com/coolproject (push)

Setting up a Remote

Clone will auto setup the remoteC:\> git clone https://git01.codeplex.com/coolprojectCloning into 'coolproject'...remote: Counting objects: 3, done.remote: Total 3 (delta 0), reused 0 (delta 0)Unpacking objects: 100% (3/3), done.C:\> cd .\coolprojectC:\CoolProject> git remote -vorigin https://git01.codeplex.com/coolproject (fetch)origin https://git01.codeplex.com/coolproject (push)

Setting up a Remote

Name remotes what you want

Setting up a Remote

Name remotes what you wantOrigin is only a convention

Branches Illustrated

A

master

B C D Ebug12

3

Branches Illustrated

A

master

origin/master

B C D Ebug12

3

Branches Illustrated

A

B C D E

master

bug123

origin/master

Branches Illustrated

A

B C D E

master

bug123

F G

origin/master

origin/master

Branches Illustrated

A

B C D E

master

bug123

> git checkout master

origin/master

Branches Illustrated

A

B C D E

master

bug123

F G

> git pull origin

origin/master

Pull = Fetch + Merge

Fetch - updates your local copy of the remote branch

Pull essentially does a fetch and then runs the merge in one step.

Branches Illustrated

A

B C D E

master

bug123

F G

origin/master

Branches Illustrated

A

B C D E

master

bug123

F G

> git checkout bug123

origin/master

Branches Illustrated

AB’

C’

D’

E’

master

bug123

F G

> git rebase master

origin/master

Branches Illustrated

AB’

C’

D’

E’

master

bug123

F G

> git checkout master

origin/master

Branches Illustrated

Amaster

bug123

F G

> git merge bug123

B’

C’

D’

E’

origin/master

Branches Illustrated

Amaster

F G

> git push origin

B’

C’

D’

E’ bug12

3

origin/master

Push

Pushes your changes upstream

Git will reject pushes if newer changes exist on remote.

Good practice: Pull then Push

Branches Illustrated

Amaster

F G B’

C’

D’

E’ bug12

3

origin/master

Branches Illustrated

Amaster

F G

> git branch -d bug123

B’

C’

D’

E’

origin/master

Adding a Remote Review

Adding a remote makes it easy to share

Pulling from the remote often helps keep you up to date

Short vs. Long-Lived BranchesLocal branches are short lived

Short vs. Long-Lived BranchesLocal branches are short livedStaying off master keeps merges simple

Short vs. Long-Lived BranchesLocal branches are short livedStaying off master keeps merges simpleEnables working on several changes at once

Short vs. Long-Lived BranchesLocal branches are short livedStaying off master keeps merges simpleEnables working on several changes at onceCreate

Commit

Merge

Delete

Short vs. Long-Lived BranchesGreat for multi-version work

Short vs. Long-Lived BranchesGreat for multi-version workFollow same rules as Master

Short vs. Long-Lived BranchesGreat for multi-version workFollow same rules as Master…Story branches

Short vs. Long-Lived BranchesGreat for multi-version workFollow same rules as Master…Story branchesIntegrate frequently

Short vs. Long-Lived BranchesGreat for multi-version workFollow same rules as Master…Story branchesIntegrate frequentlyPushed to Remotes

Branches Illustrated

E

master

origin/master

Branches Illustrated

E

master

origin/master

develop

> git branch develop

Branches Illustrated

E

master

origin/master

develop

> git push origin develop

origin/develop

Branches Illustrated

E

master

origin/master

develop

> git checkout develop

origin/develop

Branches Illustrated

E

master

origin/master

F Gdevelo

p origin/develop

Branches Illustrated

E

master

origin/master

F Gdevelo

porigin/develop

> git pull origin develop

Branches Illustrated

E

master

origin/master

F Gdevelo

porigin/

develop

> git checkout –b ideaidea

Branches Illustrated

E

master

origin/master

F Gdevelo

porigin/develop

> git commit

idea

H

Branches Illustrated

E

origin/master

F G

origin/develop idea

H

I

master

develop

Branches Illustrated

E

origin/master

F G

origin/develop idea

H

master

develop

> git pull (at least daily)

I

Branches Illustrated

E

origin/master

F G

origin/develop idea

H

master

> git checkout develop

I

develop

Branches Illustrated

E

origin/master

F G

origin/develop idea

H

master

> git merge idea (fast forward merge)

I

develop

Branches Illustrated

E

origin/master

F G

origin/develop

H

master

> git branch –d idea

I

develop

Branches Illustrated

E

origin/master

F G

origin/develop

H

master

> git push origin develop

I

develop

Merge Flow vs. Rebase Flow

E

origin/master

F G

origin/develop

H

master

> git push origin develop

I

develop

Branches Illustrated – Merge Flow

E

origin/master

F G

origin/develop

H

master

> git checkout master

I

develop

Branches Illustrated – Merge Flow

E

origin/master

F G

origin/develop

H

master

> git merge develop

I

develop

J

Branches Illustrated – Merge Flow

E

origin/master

F G

origin/develop

H

master

> git push origin

I

develop

J

Branches Illustrated – Rebase Flow

E

origin/master

F G

origin/develop

H

master

> git checkout master

I

develop

Branches Illustrated – Rebase Flow

E

origin/master

F G

origin/develop

Hmaster

> git rebase develop

I’develo

p

I

Branches Illustrated – Rebase Flow

E

origin/master

F G

origin/develop

Hmaster

> git push origin

I’develo

p

Rebase FlowE

origin/master

F G

origin/develop

Hmaster

I’develo

p

E

origin/master

F G

origin/develop

H

master

I

develop

J

Merge Flow

Short vs. Long-Lived Branches

Great for multi-version workFollow same rules as Master

…use Story branches

Define your conventions What branches do you want to

share?Branch per environment?

Deploying with Git

Deploying with Git

Developer “FTP”

Deploying with Git

Developer “FTP”Additional Branches pointing at:

Deploying with Git

Developer FTPAdditional Branches pointing at:

Test, Staging , Production

Deploying with Git

Developer FTPAdditional Branches pointing at:

Test, Staging , ProductionPost Commit Hooks Automate deployments

Cloud Providers – Git Support

AppHarborHerokuNodejitsuWindows Azure… to name a few

Simple Azure Deploy

C:\CoolProject > git remote add azure https://[email protected]/coolproject.gitC:\CoolProject > git remote -vazure https://[email protected]/coolproject.git (fetch)azure https://[email protected]/coolproject.git (push)origin https://git01.codeplex.com/coolproject (fetch)origin https://git01.codeplex.com/coolproject (push)C:\CoolProject > git push azure masterCounting objects: 3, done.Writing objects: 100% (3/3), 226 bytes, done.Total 3 (delta 0), reused 0 (delta 0)remote: New deployment received.remote: Updating branch 'master'.remote: Updating submodules.remote: Preparing deployment for commit id '7106a52771'.remote: Preparing files for deployment.remote: Deployment successful.To https://[email protected]/coolproject.git * [new branch] master -> master

Git Deployment

Simple workflow

Git Deployment

Simple workflowAdd Hooks to deploy on Commit

Git Deployment

Simple workflowAdd Hooks to deploy on CommitCan get more advanced

Git Deployment

Simple workflowAdd Hooks to deploy on CommitCan get more advancedAdd Build machines, push on success

Your Org uses TFS?

Your Org uses TFS? Sure Use Git-TFLocal workflow with Git

Your Org uses TFS? Sure Use Git-TFLocal workflow with GitPush to TFS as a Remote

Your Org uses TFS? Sure Use Git-TFLocal workflow with GitPush to TFS as a RemoteMulti-Platform and Open Source

Your Org uses TFS? Sure Use Git-TFLocal workflow with GitPush to TFS as a RemoteMulti-Platform and Open Sourcehttp://gittf.codeplex.com

Individual Developer WorkflowC:\CoolProject > git tf clone http://myserver:8080/tfs $/TeamProjectA/Main Make changes to the file in the Git repoC:\CoolProject > git commit -a -m "commit one" (commit changes locally) Make more changesC:\CoolProject > git commit -a -m "commit two"C:\CoolProject > git tf pull --rebaseC:\CoolProject > git tf checkin

Git-TF for larger teamsTFS

Tom’s Repo

Tracey’s Repo

Matt’s Repo

A B C A B C A B C

Shared Git Repo

A B C

git tf clone

git push

git clone git clone

Git-TF

Local workflow with GitPush to TFS as a RemoteMulti-Platform and Open Sourcehttp://gittf.codeplex.com

http://Git-SCM.com

Tools / ResourcesPro Git (Book) http://www.git-scm.com/book

TortoiseGit (with TortoiseMerge) http://code.google.com/p/tortoisegit

Msysgit (includes git-bash) http://code.google.com/p/msysgit

Posh-Git (for PowerShell users) http://github.com/dahlbyk/posh-git

GitScc (Visual Studio integration) http://gitscc.codeplex.com/

Windows Git Credential Store http://gitcredentialstore.codeplex.com/

GitHub for Windows http://windows.github.com/

Symposium 2013

[email protected]@mgroves84