SlideShare una empresa de Scribd logo
1 de 41
Descargar para leer sin conexión
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

Más contenido relacionado

Más de Nicola Paolucci

Git Power Routines
Git Power RoutinesGit Power Routines
Git Power Routines
Nicola Paolucci
 

Más de 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
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

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