patterns & practices Symposium 2013 Introducing Git version control into your team Mark
Symposium 2013 Abstract Over the last several years one of the biggest changes in how developers collaborate with each other has come through, of all things, their source control system. The adoption of Git has changed many of the patterns of software development. In this talk I will introduce you to the core concepts of using Git within a team, how it can improve your agility and communication.
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 Groves Principal Program Manager Developer Division
History
Created by Linus Torvalds for work on the Linux kernel ~2005
History Created by Linus Torvalds for work on the Linux kernel ~2005 Some of the companies that use git:
What is Git?
Git is a Distributed Version Control System
OROR
Git is a Content Management System
Git is a history storage system
Git is a content tracker
How ever you think about it…
Distributed Everyone has the complete history
Distributed Everything is done offline …except push/pull Everyone has the complete history
Distributed Everything is done offline Everyone has the complete history No central authority …except by convention
Distributed Everything is done offline Everyone has the complete history No central authority Changes can be shared without a server
Centralized VC vs. Distributed VC Central Server Remote Server
Branching
Forget what you know from Central VC (…TFS, SVN, Perforce...)
Branching Forget what you know from Central VC Git branch is “Sticky Note” on a graph node
Branching Forget what you know from Central VC Git branch is “Sticky Note” on a graph node All branch work takes place within the same folder within your file system.
Branching Forget what you know from Central VC Git branch is “Sticky Note” on the graph All branch work takes place within the same folder within your file system. When you switch branches you are moving the “Sticky Note”
Initialization C:\> mkdir CoolProject C:\> cd CoolProject C:\CoolProject > git init Initialized empty Git repository in C:/CoolProject/.git C:\CoolProject > notepad README.txt C:\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 README.txt
Branches Illustrated master A > git commit –m ‘my first commit’
Branches Illustrated master > git commit (x2) ABC
Branches Illustrated bug123 master > git checkout –b bug123 ABC
Branches Illustrated master > git commit (x2) ABC DE bug123
Branches Illustrated master > git checkout master ABC DE bug123
Branches Illustrated bug123 master > git merge bug123 ABCDE
Branches Illustrated master > git branch -d bug123 ABCDE
Branches Illustrated master ABCDE FG bug456
Branches Illustrated master ABCDE FG bug456 > git checkout master
Branches Illustrated master ABCDE FG > git merge bug456 H bug456
Branches Illustrated master ABCDE FG > git branch -d bug456 H
Branches Illustrated master ABCDE FG bug456
Branches Illustrated master ABCDE > git rebase master F’ G’ bug456
Branches Illustrated master ABCDE > git checkout master > git merge bug456 > git checkout master > git merge bug456 F’ G’ bug456
Branching Review
Quick and Easy to create ‘Feature’ Branches
Branching Review Local branches are very powerful Quick and Easy to create ‘Feature’ Branches
Branching Review Local branches are very powerful Quick 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 AB C ABCABC ABC
Adding a Remote
Sharing commits My Local Repo Tom’s Repo Tracey’s Repo Matt’s Repo AB C ABCABC ABC Remote Repo A A B B C C D D D D D D
Setting up a Remote
Adding a remote to an existing local repo C:\CoolProject > git remote add origin C:\CoolProject > git remote -v origin (fetch) origin (push)
Setting up a Remote Clone will auto setup the remote C:\> git clone Cloning into 'coolproject'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. C:\> cd.\coolproject C:\CoolProject> git remote -v origin (fetch) origin (push)
Setting up a Remote Name remotes what you want
Setting up a Remote Name remotes what you want Origin is only a convention
Branches Illustrated A master BCDE bug123
Branches Illustrated A master origin/master BCDE bug123
Branches Illustrated A B B C C D D E E master bug123 origin/master
Branches Illustrated A B B C C D D E E master bug123 F F G G origin/master
Branches Illustrated A B B C C D D E E master bug123 > git checkout master origin/master
Branches Illustrated A B B C C D D E E master bug123 FG > 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 B C C D D E E master bug123 FG origin/master
Branches Illustrated A B B C C D D E E master bug123 FG > git checkout bug123 origin/master
Branches Illustrated A B’ C’ D’ E’ master bug123 FG > git rebase master origin/master
Branches Illustrated A B’ C’ D’ E’ master bug123 FG > git checkout master origin/master
Branches Illustrated A master bug123 FG > git merge bug123 B’ C’ D’ E’ origin/master
Branches Illustrated A master FG > git push origin B’ C’ D’ E’ bug123 origin/master
Push Pushes your changes upstream Git will reject pushes if newer changes exist on remote. Good practice: Pull then Push
Branches Illustrated A master FG B’ C’ D’ E’ bug123 origin/master
Branches Illustrated A master FG > 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 Branches Local branches are short lived
Short vs. Long-Lived Branches Local branches are short lived Staying off master keeps merges simple
Short vs. Long-Lived Branches Local branches are short lived Staying off master keeps merges simple Enables working on several changes at once
Short vs. Long-Lived Branches Local branches are short lived Staying off master keeps merges simple Enables working on several changes at once CreateCommitMerge Delete
Short vs. Long-Lived Branches Great for multi-version work
Short vs. Long-Lived Branches Great for multi-version work Follow same rules as Master
Short vs. Long-Lived Branches Great for multi-version work Follow same rules as Master…Story branches
Short vs. Long-Lived Branches Great for multi-version work Follow same rules as Master…Story branches Integrate frequently
Short vs. Long-Lived Branches Great for multi-version work Follow same rules as Master…Story branches Integrate frequently Pushed 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 F G G develop origin/develop
Branches Illustrated E master origin/master FG develop origin/develop > git pull origin develop
Branches Illustrated E master origin/master FG develop origin/develop > git checkout –b idea idea
Branches Illustrated E master origin/master FG develop origin/develop > git commit idea H
Branches Illustrated E origin/master FG origin/develop idea H I I master develop
Branches Illustrated E origin/master FG origin/develop idea H master develop > git pull (at least daily) I
Branches Illustrated E origin/master FG origin/develop idea H master > git checkout develop I develop
Branches Illustrated E origin/master FG origin/develop idea H master > git merge idea (fast forward merge) I develop
Branches Illustrated E origin/master FG origin/develop H master > git branch –d idea I develop
Branches Illustrated E origin/master FG origin/develop H master > git push origin develop I develop
Merge Flow vs. Rebase Flow E origin/master FG origin/develop H master > git push origin develop I develop
Branches Illustrated – Merge Flow E origin/master FG origin/develop H master > git checkout master I develop
Branches Illustrated – Merge Flow E origin/master FG origin/develop H master > git merge develop I develop J
Branches Illustrated – Merge Flow E origin/master FG origin/develop H master > git push origin I develop J
Branches Illustrated – Rebase Flow E origin/master FG origin/develop H master > git checkout master I develop
Branches Illustrated – Rebase Flow E origin/master FG origin/develop H master > git rebase develop I’ develop I I
Branches Illustrated – Rebase Flow E origin/master FG origin/develop H master > git push origin I’ develop
Rebase Flow E origin/master FG origin/develop H master I’ develop E origin/master FG origin/develop H master I develop J Merge Flow
Short vs. Long-Lived Branches Great for multi-version work Follow same rules as Master …use Story branches Define your conventions What branches do you want to share? Branch per environment?
Deploying with Git
Developer “FTP”
Deploying with Git Developer “FTP” Additional Branches pointing at:
Deploying with Git Developer FTP Additional Branches pointing at: Test, Staging, Production
Deploying with Git Developer FTP Additional Branches pointing at: Test, Staging, Production Post Commit Hooks Automate deployments
Cloud Providers – Git Support AppHarbor Heroku Nodejitsu Windows Azure … to name a few
Simple Azure Deploy
C:\CoolProject > git remote add azure C:\CoolProject > git remote -v azure (fetch) azure (push) origin (fetch) origin (push) C:\CoolProject > git push azure master Counting 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 * [new branch] master -> master
Git Deployment Simple workflow
Git Deployment Simple workflow Add Hooks to deploy on Commit
Git Deployment Simple workflow Add Hooks to deploy on Commit Can get more advanced
Git Deployment Simple workflow Add Hooks to deploy on Commit Can get more advanced Add Build machines, push on success
Your Org uses TFS?
Your Org uses TFS? Sure Use Git- TF Local workflow with Git
Your Org uses TFS? Sure Use Git- TF Local workflow with Git Push to TFS as a Remote
Your Org uses TFS? Sure Use Git- TF Local workflow with Git Push to TFS as a Remote Multi-Platform and Open Source
Your Org uses TFS? Sure Use Git- TF Local workflow with Git Push to TFS as a Remote Multi-Platform and Open Source
Individual Developer Workflow C:\CoolProject > git tf clone $/TeamProjectA/Main Make changes to the file in the Git repo C:\CoolProject > git commit -a -m "commit one" (commit changes locally) Make more changes C:\CoolProject > git commit -a -m "commit two" C:\CoolProject > git tf pull --rebase C:\CoolProject > git tf checkin
Git-TF for larger teams TFS Tom’s Repo Tracey’s Repo Matt’s Repo ABCABC ABC Shared Git Repo A A B B C C git tf clone git push git clone
Git-TF Local workflow with Git Push to TFS as a Remote Multi-Platform and Open Source
Tools / Resources Pro Git (Book) TortoiseGit (with TortoiseMerge) Msysgit (includes git-bash) Posh-Git (for PowerShell users) GitScc (Visual Studio integration) Windows Git Credential Store GitHub for Windows
Symposium 2013