patterns & practices symposium 2013 introducing git version control into your team mark groves...
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
History
Created by Linus Torvalds for work on the Linux kernel ~2005Some of the companies that use git:
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
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
Branching Review
Local branches are very powerfulQuick and Easy to create ‘Feature’ Branches
Rebase is not scary
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
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)
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.
Push
Pushes your changes upstream
Git will reject pushes if newer changes exist on remote.
Good practice: Pull then Push
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 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 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
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 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
Developer FTPAdditional Branches pointing at:
Test, Staging , ProductionPost Commit Hooks Automate deployments
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 workflowAdd Hooks to deploy on CommitCan get more advancedAdd Build machines, push on success
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
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/