SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
Git Power Routines
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Master the art and practice of DVCS
@durdn
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
@durdn
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
@durdn
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
Obvious!
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
@durdn
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
@durdn
What is a rebase?
It’s a way to replay commits, one
by one, on top of a branch
master
feature
@durdn
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
@durdn
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 $@;
@durdn
Embrace useful merge strategies
Merging the right way can go a long way…
@durdn
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
@durdn
Let’s talk about merge strategies!
git has breadth of choice on how to
merge changes!
recursiveresolve octopus
subtreeours yours?
@durdn
merge strategy: ours
master
feature
Records a merge but skips incoming changes
IGNORE!
strategy --ours is useful
to promote recent
branches to master
@durdn
feature
What is a fast-forward merge?
master
It will just shift the HEAD tag
feature
m
aster
@durdn
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
@durdn
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
@durdn
Switch context at will
Git stash power techniques
@durdn
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
@durdn
Thank you!
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Twitter: @durdn

Contenu connexe

Tendances

Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
Docker, Inc.
 

Tendances (20)

ContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven InfrastructureContainerCon - Test Driven Infrastructure
ContainerCon - Test Driven Infrastructure
 
JavaCro'14 - Continuous delivery of Java EE applications with Jenkins and Doc...
JavaCro'14 - Continuous delivery of Java EE applications with Jenkins and Doc...JavaCro'14 - Continuous delivery of Java EE applications with Jenkins and Doc...
JavaCro'14 - Continuous delivery of Java EE applications with Jenkins and Doc...
 
Code Reviews vs. Pull Requests
Code Reviews vs. Pull RequestsCode Reviews vs. Pull Requests
Code Reviews vs. Pull Requests
 
Game of Codes: the Battle for CI
Game of Codes: the Battle for CIGame of Codes: the Battle for CI
Game of Codes: the Battle for CI
 
Git branching-model
Git branching-modelGit branching-model
Git branching-model
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
 
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
 
How we git - commit policy and code review
How we git - commit policy and code reviewHow we git - commit policy and code review
How we git - commit policy and code review
 
Open Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git HubOpen Source Collaboration With Git And Git Hub
Open Source Collaboration With Git And Git Hub
 
Git
GitGit
Git
 
Git
GitGit
Git
 
Automated Deployments
Automated DeploymentsAutomated Deployments
Automated Deployments
 
Introduction to Automated Deployments with Ansible
Introduction to Automated Deployments with AnsibleIntroduction to Automated Deployments with Ansible
Introduction to Automated Deployments with Ansible
 
Git best practices 2016
Git best practices 2016Git best practices 2016
Git best practices 2016
 
Trunk-Based Development
Trunk-Based DevelopmentTrunk-Based Development
Trunk-Based Development
 
CI is dead, long live CI
CI is dead, long live CICI is dead, long live CI
CI is dead, long live CI
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Building Jenkins Pipelines at Scale
Building Jenkins Pipelines at ScaleBuilding Jenkins Pipelines at Scale
Building Jenkins Pipelines at Scale
 
CI/CD with Rancher CLI + Jenkins
CI/CD with Rancher CLI + JenkinsCI/CD with Rancher CLI + Jenkins
CI/CD with Rancher CLI + Jenkins
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and ComposeDockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
 

Similaire à Git Power Routines

slides.pdf
slides.pdfslides.pdf
slides.pdf
vidsvagi
 

Similaire à Git Power Routines (20)

Transformative Git Practices
Transformative Git PracticesTransformative Git Practices
Transformative Git Practices
 
Becoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola PaolucciBecoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola Paolucci
 
That's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICThat's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETIC
 
Training: Day Two - Eclipse, Git, Maven
Training: Day Two - Eclipse, Git, MavenTraining: Day Two - Eclipse, Git, Maven
Training: Day Two - Eclipse, Git, Maven
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAdvanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Git presentation
Git presentationGit presentation
Git presentation
 
slides.pdf
slides.pdfslides.pdf
slides.pdf
 
slides.pdf
slides.pdfslides.pdf
slides.pdf
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for Git
 
Ninja Git: Save Your Master
Ninja Git: Save Your MasterNinja Git: Save Your Master
Ninja Git: Save Your Master
 
Git
GitGit
Git
 
Troubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineersTroubleshooting tips from docker support engineers
Troubleshooting tips from docker support engineers
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it AgainGit Anti-Patterns: How To Mess Up With Git and Love it Again
Git Anti-Patterns: How To Mess Up With Git and Love it Again
 
Working with Git
Working with GitWorking with Git
Working with Git
 

Dernier

原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
Asmae Rabhi
 

Dernier (20)

原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 

Git Power Routines