SlideShare a Scribd company logo
1 of 41
Download to read offline
Master the art and practice of DVCS
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Power routines of experienced Git users
REMOVE BINARIES
Follow along, solve real world daily
version control situations
CONFLICT RESOLUTION
MERGE STRATEGIES
INTERACTIVE COMMITS
AMEND AND REBASE
ADVENTURE AWAITS
Follow along the adventure
This session won’t be interactive but you can
follow along and try to beat me to tasks by
cloning this repository
git clone 
git@bitbucket.org:nicolapaolucci/starwars-summary.git
About the sample project
ADVENTURE AWAITS
House keeping [1]
Get a nice prompt: Liquid prompt is awesome
http://bit.do/liquid-prompt
ADVENTURE AWAITS
House keeping [2]
If you are creating a new repository, start with an
empty commit and tag it
git commit -m"[empty] Initial commit" --allow-empty
git tag initial <first-sha-1> -m"Tag initial commit"
ADVENTURE AWAITS
House keeping [3]
To speed up the typing I have created a few
aliases that we will re-use throughout
ls = log --decorate --oneline
ll = log --decorate --numstat
http://bit.do/gitconfig
Common and not so common
un-doings and re-doings
Amending and Re-basing
Credit: Emma Jane Hogbin Westby
@emmajanehw
Credit: Emma Jane Hogbin Westby
@emmajanehw
THEORY
Always think of these
Work directory
Which tree does my command affect?
Index or
Staging area
Local repository
(.git) Remotes
UNDOINGS
Memorise or alias this to amend quickly
Amend the last commit with everything I have
here uncommitted and new
caa = commit -a --amend -C HEAD
THEORY
Default git reset is of type mixed…
Work directory
Which tree does my command affect?
Index or
Staging area
Local repository
(.git)
HEAD
master
git reset HEAD~
HEAD
HEAD
HEAD
changes
THEORY
Default git reset is a mixed reset…
Work directory
Which tree does my command affect?
Index or
Staging area
Local repository
(.git)
HEAD
master
git reset HEAD~
HEAD
HEAD
Ancestry references
You can specify commits via their ancestry.
The more common examples are
HEAD^ = the parent of commit HEAD
HEAD~2 = traverses the first
parent 2 times, finds
the grand parent
Now let’s change a
commit in the past
What is a rebase?
It’s a way to replay commits, one
by one, on top of a branch
master
feature
What is an
--interactive rebase?
Helps you clean up your private branches
before publishing them
reword
fixup
pick
squash
edit
exec
For complex history
cleanup use
git filter-branch or BFG
UNDOINGS
BFG Repo-Cleaner is a nice option
http://bit.do/bfg
Let’s learn to solve conflicts
Believe me, it can be done without tears and sweat.
CONFLICT RESOLUTION
A word on terminology
Current checked
out branch
--ours
What do ours and theirs mean when solving conflicts?
Commit coming in
(i.e. via merge)
--theirs
CONFLICT RESOLUTION
Basics for easy conflict resolution
The common commands are:
$ git checkout --ours/--theirs <file>
Check back out our own/their own version of the file
$ git add <file>
Add the change to the index will resolve the conflict
CONFLICT RESOLUTION
Aliases for easy conflict resolution
Add these to [alias] in .gitconfig:
ours = "!f() { 

}; f"
git checkout --ours $@ && git add $@;
Embrace useful merge strategies
Merging the right way can go a long way…
What is a merge?
Merge
commit
master
feature
merges keep the context of the
feature’s commits
feature
m
aster
tree f362c42032aff677c1a09c3f070454df5b411239
parent 49a906f5722ad446a131778cea52e3fda331b706
parent bd1174cd0f30fe9be9efdd41dcd56256340f230e
author Marcus Bertrand <mbertrand@atlassian.com>
1409002123 -0700
committer Marcus Bertrand <mbertrand@atlassian.com>
1409002123 -0700
Merge branch 'foo/mybranch'
.git/objects/36/80d8c8fd182f97cb0e75045e2fed5c7b7613ed
commit
Anatomy of a merge
Let’s talk about merge strategies!
git has breadth of choice on how to
merge changes!
recursiveresolve octopus
subtreeours yours?
merge strategy: ours
master
feature
Records a merge but skips incoming changes
IGNORE!
strategy --ours is useful
to promote recent
branches to master
feature
What is a fast-forward merge?
master
It will just shift the HEAD tag
feature
m
aster
What is a fast-forward merge?
master
It will just shift the HEAD tag
feature
m
aster
Octopus merge is
nice for staging
servers.
UNDOINGS
Octopus Merge can be very useful
http://bit.do/git-octopus
UNDOINGS
Octopus Merge can be very useful
Interactive add (and commit)
Splitting commits semantically in flight!
Stage this hunk [y,n,q,a,d,/,s,e,?]? ?
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
Switch context at will
Git stash power techniques
git stash is awesome
It’s a way to temporarily store your
unsaved work on a stack of patches
stash@{0}
stash@{1}
stash@{2}
stash@{3}
git stash save
Thank you!
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Twitter: @durdn

More Related Content

More from Nicola Paolucci

The age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster managementThe age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster managementNicola Paolucci
 
Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)Nicola Paolucci
 
Be a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeBe a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeNicola Paolucci
 
Ninja Git: Save Your Master
Ninja Git: Save Your MasterNinja Git: Save Your Master
Ninja Git: Save Your MasterNicola Paolucci
 
Real World Git Workflows - EclipseCon Europe 2013
Real World Git Workflows - EclipseCon Europe 2013Real World Git Workflows - EclipseCon Europe 2013
Real World Git Workflows - EclipseCon Europe 2013Nicola Paolucci
 

More from Nicola Paolucci (7)

The age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster managementThe age of orchestration: from Docker basics to cluster management
The age of orchestration: from Docker basics to cluster management
 
Git Power Routines
Git Power RoutinesGit Power Routines
Git Power Routines
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)Be a better developer with Docker (revision 3)
Be a better developer with Docker (revision 3)
 
Be a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the tradeBe a happier developer with Docker: Tricks of the trade
Be a happier developer with Docker: Tricks of the trade
 
Ninja Git: Save Your Master
Ninja Git: Save Your MasterNinja Git: Save Your Master
Ninja Git: Save Your Master
 
Real World Git Workflows - EclipseCon Europe 2013
Real World Git Workflows - EclipseCon Europe 2013Real World Git Workflows - EclipseCon Europe 2013
Real World Git Workflows - EclipseCon Europe 2013
 

Recently uploaded

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Power routines of experienced Git users

  • 1. Master the art and practice of DVCS NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Power routines of experienced Git users
  • 2. REMOVE BINARIES Follow along, solve real world daily version control situations CONFLICT RESOLUTION MERGE STRATEGIES INTERACTIVE COMMITS AMEND AND REBASE
  • 3. ADVENTURE AWAITS Follow along the adventure This session won’t be interactive but you can follow along and try to beat me to tasks by cloning this repository git clone git@bitbucket.org:nicolapaolucci/starwars-summary.git
  • 5. ADVENTURE AWAITS House keeping [1] Get a nice prompt: Liquid prompt is awesome http://bit.do/liquid-prompt
  • 6. ADVENTURE AWAITS House keeping [2] If you are creating a new repository, start with an empty commit and tag it git commit -m"[empty] Initial commit" --allow-empty git tag initial <first-sha-1> -m"Tag initial commit"
  • 7. ADVENTURE AWAITS House keeping [3] To speed up the typing I have created a few aliases that we will re-use throughout ls = log --decorate --oneline ll = log --decorate --numstat http://bit.do/gitconfig
  • 8. Common and not so common un-doings and re-doings Amending and Re-basing
  • 9. Credit: Emma Jane Hogbin Westby @emmajanehw
  • 10. Credit: Emma Jane Hogbin Westby @emmajanehw
  • 11. THEORY Always think of these Work directory Which tree does my command affect? Index or Staging area Local repository (.git) Remotes
  • 12. UNDOINGS Memorise or alias this to amend quickly Amend the last commit with everything I have here uncommitted and new caa = commit -a --amend -C HEAD
  • 13. THEORY Default git reset is of type mixed… Work directory Which tree does my command affect? Index or Staging area Local repository (.git) HEAD master git reset HEAD~ HEAD HEAD HEAD
  • 14. changes THEORY Default git reset is a mixed reset… Work directory Which tree does my command affect? Index or Staging area Local repository (.git) HEAD master git reset HEAD~ HEAD HEAD
  • 15. Ancestry references You can specify commits via their ancestry. The more common examples are HEAD^ = the parent of commit HEAD HEAD~2 = traverses the first parent 2 times, finds the grand parent
  • 16. Now let’s change a commit in the past
  • 17. What is a rebase? It’s a way to replay commits, one by one, on top of a branch master feature
  • 18. What is an --interactive rebase? Helps you clean up your private branches before publishing them reword fixup pick squash edit exec
  • 19. For complex history cleanup use git filter-branch or BFG
  • 20. UNDOINGS BFG Repo-Cleaner is a nice option http://bit.do/bfg
  • 21. Let’s learn to solve conflicts Believe me, it can be done without tears and sweat.
  • 22. CONFLICT RESOLUTION A word on terminology Current checked out branch --ours What do ours and theirs mean when solving conflicts? Commit coming in (i.e. via merge) --theirs
  • 23. CONFLICT RESOLUTION Basics for easy conflict resolution The common commands are: $ git checkout --ours/--theirs <file> Check back out our own/their own version of the file $ git add <file> Add the change to the index will resolve the conflict
  • 24. CONFLICT RESOLUTION Aliases for easy conflict resolution Add these to [alias] in .gitconfig: ours = "!f() { }; f" git checkout --ours $@ && git add $@;
  • 25. Embrace useful merge strategies Merging the right way can go a long way…
  • 26. What is a merge? Merge commit master feature merges keep the context of the feature’s commits feature m aster
  • 27. tree f362c42032aff677c1a09c3f070454df5b411239 parent 49a906f5722ad446a131778cea52e3fda331b706 parent bd1174cd0f30fe9be9efdd41dcd56256340f230e author Marcus Bertrand <mbertrand@atlassian.com> 1409002123 -0700 committer Marcus Bertrand <mbertrand@atlassian.com> 1409002123 -0700 Merge branch 'foo/mybranch' .git/objects/36/80d8c8fd182f97cb0e75045e2fed5c7b7613ed commit Anatomy of a merge
  • 28. Let’s talk about merge strategies! git has breadth of choice on how to merge changes! recursiveresolve octopus subtreeours yours?
  • 29. merge strategy: ours master feature Records a merge but skips incoming changes IGNORE!
  • 30. strategy --ours is useful to promote recent branches to master
  • 31. feature What is a fast-forward merge? master It will just shift the HEAD tag feature m aster
  • 32. What is a fast-forward merge? master It will just shift the HEAD tag feature m aster
  • 33. Octopus merge is nice for staging servers.
  • 34. UNDOINGS Octopus Merge can be very useful http://bit.do/git-octopus
  • 35. UNDOINGS Octopus Merge can be very useful
  • 36. Interactive add (and commit) Splitting commits semantically in flight!
  • 37. Stage this hunk [y,n,q,a,d,/,s,e,?]? ? y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk or any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk or any later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
  • 38. Switch context at will Git stash power techniques
  • 39. git stash is awesome It’s a way to temporarily store your unsaved work on a stack of patches stash@{0} stash@{1} stash@{2} stash@{3} git stash save
  • 40.
  • 41. Thank you! NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Twitter: @durdn