SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PDF
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
PDF
JavaCro'14 - Continuous delivery of Java EE applications with Jenkins and Doc...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PDF
Code Reviews vs. Pull Requests
Atlassian
 
PDF
Game of Codes: the Battle for CI
Atlassian
 
KEY
Git branching-model
Aaron Huang
 
PPTX
Git branching strategies
jstack
 
PDF
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
CloudBees
 
KEY
How we git - commit policy and code review
Ruben Tan
 
PPT
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
PDF
Git
Mayank Patel
 
PPTX
Git
Shinu Suresh
 
PPTX
Automated Deployments
Martin Etmajer
 
PPTX
Introduction to Automated Deployments with Ansible
Martin Etmajer
 
PDF
Git best practices 2016
Otto Kekäläinen
 
PDF
Trunk-Based Development
Bryan Liu
 
PDF
CI is dead, long live CI
Frédéric Lepied
 
PDF
Git and git hub
Sebastiaan Deckers
 
PPTX
CI/CD with Rancher CLI + Jenkins
Go Chiba
 
PDF
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
Docker, Inc.
 
PDF
Microservices with Kubernetes, Docker, and Jenkins
Rafael Benevides
 
ContainerCon - Test Driven Infrastructure
Yury Tsarev
 
JavaCro'14 - Continuous delivery of Java EE applications with Jenkins and Doc...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Code Reviews vs. Pull Requests
Atlassian
 
Game of Codes: the Battle for CI
Atlassian
 
Git branching-model
Aaron Huang
 
Git branching strategies
jstack
 
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
CloudBees
 
How we git - commit policy and code review
Ruben Tan
 
Open Source Collaboration With Git And Git Hub
Nick Quaranto
 
Automated Deployments
Martin Etmajer
 
Introduction to Automated Deployments with Ansible
Martin Etmajer
 
Git best practices 2016
Otto Kekäläinen
 
Trunk-Based Development
Bryan Liu
 
CI is dead, long live CI
Frédéric Lepied
 
Git and git hub
Sebastiaan Deckers
 
CI/CD with Rancher CLI + Jenkins
Go Chiba
 
DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
Docker, Inc.
 
Microservices with Kubernetes, Docker, and Jenkins
Rafael Benevides
 

Similar to Git Power Routines (20)

PPTX
MakingGitWorkForYou
Kwen Peterson
 
PPTX
Introduction to Git and GitHub
Bioinformatics and Computational Biosciences Branch
 
PDF
Git of every day
Alan Descoins
 
PPTX
Git_new.pptx
BruceLee275640
 
PDF
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
PPTX
Git workshop
Mateusz Galazyn
 
PPTX
Git One Day Training Notes
glen_a_smith
 
PPTX
Git walkthrough
Bimal Jain
 
PDF
Source Code Management with Git
Things Lab
 
PDF
Did you git yet?
Michael Fong
 
PPTX
Session git
Roni Saha
 
PPTX
Git-ing out of your git messes
Katie Sylor-Miller
 
PDF
Git training v10
Skander Hamza
 
PDF
Git tutorial
mobaires
 
PDF
Advanced Git Tutorial
Sage Sharp
 
PDF
Git and github 101
Senthilkumar Gopal
 
PDF
Advanced Git - Functionality and Features
All Things Open
 
PDF
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Atlassian
 
PDF
Don't fear the rebase
Giorgio Cefaro
 
PPTX
Techoalien git
Aditya Tiwari
 
MakingGitWorkForYou
Kwen Peterson
 
Git of every day
Alan Descoins
 
Git_new.pptx
BruceLee275640
 
Git: Overview, Pitfalls, Best Practices
Jeremy Leisy
 
Git workshop
Mateusz Galazyn
 
Git One Day Training Notes
glen_a_smith
 
Git walkthrough
Bimal Jain
 
Source Code Management with Git
Things Lab
 
Did you git yet?
Michael Fong
 
Session git
Roni Saha
 
Git-ing out of your git messes
Katie Sylor-Miller
 
Git training v10
Skander Hamza
 
Git tutorial
mobaires
 
Advanced Git Tutorial
Sage Sharp
 
Git and github 101
Senthilkumar Gopal
 
Advanced Git - Functionality and Features
All Things Open
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Atlassian
 
Don't fear the rebase
Giorgio Cefaro
 
Techoalien git
Aditya Tiwari
 
Ad

More from Nicola Paolucci (7)

PDF
Transformative Git Practices
Nicola Paolucci
 
PDF
The age of orchestration: from Docker basics to cluster management
Nicola Paolucci
 
PDF
Becoming a Git Master
Nicola Paolucci
 
PDF
Be a better developer with Docker (revision 3)
Nicola Paolucci
 
PDF
Be a happier developer with Docker: Tricks of the trade
Nicola Paolucci
 
PDF
Ninja Git: Save Your Master
Nicola Paolucci
 
PDF
Real World Git Workflows - EclipseCon Europe 2013
Nicola Paolucci
 
Transformative Git Practices
Nicola Paolucci
 
The age of orchestration: from Docker basics to cluster management
Nicola Paolucci
 
Becoming a Git Master
Nicola Paolucci
 
Be a better developer with Docker (revision 3)
Nicola Paolucci
 
Be a happier developer with Docker: Tricks of the trade
Nicola Paolucci
 
Ninja Git: Save Your Master
Nicola Paolucci
 
Real World Git Workflows - EclipseCon Europe 2013
Nicola Paolucci
 
Ad

Recently uploaded (20)

PPTX
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
PDF
DevOps Design for different deployment options
henrymails
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PPTX
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
PPTX
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
PPTX
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PPT
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PPTX
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PDF
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 
Cost_of_Quality_Presentation_Software_Engineering.pptx
farispalayi
 
DevOps Design for different deployment options
henrymails
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
英国假毕业证诺森比亚大学成绩单GPA修改UNN学生卡网上可查学历成绩单
Taqyea
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
sajflsajfljsdfljslfjslfsdfas;fdsfksadfjlsdflkjslgfs;lfjlsajfl;sajfasfd.pptx
theknightme
 
unit 2_2 copy right fdrgfdgfai and sm.pptx
nepmithibai2024
 
西班牙武康大学毕业证书{UCAMOfferUCAM成绩单水印}原版制作
Taqyea
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
Computer Securityyyyyyyy - Chapter 1.ppt
SolomonSB
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
Orchestrating things in Angular application
Peter Abraham
 
一比一原版(LaTech毕业证)路易斯安那理工大学毕业证如何办理
Taqyea
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Apple_Environmental_Progress_Report_2025.pdf
yiukwong
 

Git Power Routines