Knowledge. People. Solutions. Dennis Doomen (@ddoomen) 29-1-2016 Git like a Pro
Knowledge.
People.
Solutions.
Dennis Doomen (@ddoomen)
29-1-2016
Git like a Pro
About Me
2
• 19 years in business
• C#/.NET developer with roots in C++
• TDD/BDD, DDD, Event Sourcing, CQRS, OO, Design
Patterns, Architecture
• Scrum/XP/Kanban, ALM
• Occasional Speaker
• www.csharpcodingguidelines.com
• www.fluentassertions.com
• www.continuousimprover.com
29-1-2016
Development Workflows
Git in a Nutshell
4
EBA
C D F
G
feature
master1.3.0
Commit
TagBranch
Head
Other
Parent
Parent
d683499b006c422974886
04b352f206a4c0e1382d683499b
29-1-2016
Shared MasterBranches
Commits Tags
GitHub
Bitbucket,
Visual Studio Online,
TFS
Branches
Commits Tags
Remotes
John’s Clone Mike’s Clone
Branches
Commits Tags
Remotes
Branches
Commits Tags
Remotes
Jane’s Clone
Local Machine
git push mastergit pull master git push master
git clone
git pull master
git push master
git pull master
29-1-2016
Shared Feature BranchBranches
Commits Tags
Branches
Commits Tags
Remotes
John’s Clone Mike’s Clone
Branches
Commits Tags
Remotes
Branches
Commits Tags
Remotes
Jane’s Clone
git push feat1 git push mastergit pull feat1
git push feat1 git pull feat1
git checkout master
git merge feat1git checkout –b feat1
GitHub
Bitbucket,
Visual Studio Online,
TFS
Local Machine
29-1-2016
Shared Feature Branch with Pull RequestBranches
Commits Tags
Branches
Commits Tags
Remotes
John’s Clone Mike’s Clone
Branches
Commits Tags
Remotes
Branches
Commits Tags
Remotes
Jane’s Clone
git push feat1 git push feat1git pull feat1
git push feat1 git pull feat1
git checkout –b feat1
GitHub
Bitbucket,
Visual Studio Online,
TFS
Local Machine
feat1 -> master
29-1-2016
Shared Fork with Pull Request
Branches
Commits Tags
Branches
Commits Tags
Remotes
John’s Clone Mike’s Clone
Branches
Commits Tags
Remotes
Branches
Commits Tags
Remotes
Jane’s Clone
git push john feat1
git push john feat1
fork
git push john feat1 git pull john feat1
git checkout –b feat1
GitHub
Bitbucket,
Visual Studio Online,
TFS
Local Machine
john/feat1 -> main/master
Branches
Commits Tags John’s Fork
git pull john feat1
29-1-2016
Tools
Popular Tools
• Atlassian SourceTree
• Git Extensions
• Github Desktop
• SmartGit
• Visual Studio 2013/2015
• PowerShell + PoshGit + Jump-Location
• Bash
• GitKraken
10
29-1-2016
Aliasing like a Pro
Aliasing like a Pro
• git cob
• git cm
• git wipe
• git amend
• git bclean, git bdone
• git save, git undo
• git up, git fa
• Stored in – %userprofile%\.gitconfig
– .git\config
12
29-1-2016
Release Strategies
Semantic Versioning
14
2.3.1Breaking
Changes
Backwards
Compatible
Changes
Patches
GitHubFlow
15
Source: https://blog.oio.de/2014/09/22/git-workflows-teil-2-workflows-meistern/
GitFlow
16
29-1-2016
GitVersion
29-1-2016
Merging Strategies
Simple Merge
19
EBA
C D F
G
feature
master
git merge feature
Merge commit
Fast-Forward Merge
20
BA
C D Efeature
master
git merge feature
Squashing Merge
21
EBA
C D F
G
feature
master
git merge feature --squash
Merge commit
Cherry-Pick
22
EBA
C D F
D’
feature
master
git cherry-pick D
commit
Rebase Merge
23
EBA
C D Efeature
master
C’ D’ E’
git rebase master
feature
git merge feature
Discard Merge
24
EBA
C D F
G
feature
master
git merge feature –-strategy ours
empty commit (!)
29-1-2016
The Beauty of a Clean History
Keep your history clean
Source: http://www.tugberkugurlu.com/tags/git
• Traceability
• Reviewability
• Historical drilling
• Rebasing
• Reverting
• git bisect
26
29-1-2016
Divide and Conquer your
Branches
Move local changes to new branch
28
?BA
feature
master
git checkout –b feature
Uncommitted
changes
?
Move committed changes to new branch
29
CBA
feature
master git checkout –b feature
git reset B --hard
29-1-2016
Extract committed changes
CBA
Bfeature
master
C’
git checkout B –b feature
git rebase A -i
29-1-2016
Extract committed changes (alternative)
FBA
feature
master
C’
git checkout A –b feature
C D E
git cherry-pick C
F’D’ E’
git rebase B -i
29-1-2016
Not for the faint of heart
29-1-2016
Submodules
Branches
Commits Tags
Remotes
Branches
Commits
Tags
Remotes
.gitmodules
GitHub
Bitbucket,
Visual Studio Online,
TFS
Local Machine
Branches
Commits Tags
Branches
Commits Tags
.\subrepo
git submodule add repo-urlgit clone –recursive sub-repo-urlgit config submodule.subrepo.url alternative-urlgit submodule update --remote
[submodule “subrepo"] path = .\subrepourl = https://github.com/subrepobranch = feature
git config submodule.DbConnector.url PRIVATE_URL
Advanced
• git commit –-all –amend
• git push --force
• git reflog
• .gitignore/.gitattributes tuning
• git bisect
• git worktree add -b hot-fix ../hotfix master
• git clone –-depth 0
• git rerere (“reuse recording resolution”)
• git subtree
• git notes (supported by Github)
• git rebase --autostash
34
29-1-2016
How we like to work
29-1-2016
How I like to work
Central Repo
John’s fork
Dean’s fork
mast
er
mast
er
share
d
Dean’s changes
Mike’s changes
Task
1
git rebase -i
Mike’s fork
Task
2
git rebase -i
Pull Request
Pull Request
Task
3
Pull Request
Pull Request
John’s changes
29-1-2016
Resources
• A scalable software development organization by using Githttp://www.continuousimprover.com/2015/03/a-scalable-software-development.html
• Why should abandon TFS Source Control and adopt Githttp://www.continuousimprover.com/2015/06/why-you-should-abandon-tfs-source.html
• Semantic Mergehttps://www.semanticmerge.com/
• Git Aliaseshttp://haacked.com/archive/2014/07/28/github-flow-aliases/
• Awesome Git tutorialshttp://pcottle.github.io/learnGitBranching/
• GitVersionhttps://github.com/GitTools/GitVersion
• Semantic Versioninghttp://semver.org/
• GitFlow vs GitHubFlowhttp://gitversion.readthedocs.org/en/latest/git-branching-strategies/
• Pro Git (the book)https://git-scm.com/book/en/v2
38
How to find me?
39
• @ddoomen
• www.continuousimprover.com
• www.csharpcodingguidelines.com
• github.com/dennisdoomen
• www.fluentassertions.com
29-1-2016
Thanks!
Knowledge. People. Solutions.