Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 STRATEGIE...
ADVENTURE AWAITS
Follow along the adventure
This session won’t be interactive but you can
follow along and try to beat me ...
@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 ...
ADVENTURE AWAITS
House keeping [3]
To speed up the typing I have created a few
aliases that we will re-use throughout
ls =...
@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
(.gi...
UNDOINGS
Memorise or alias this to amend quickly
Amend the last commit with everything I have
here uncommitted and new
caa...
THEORY
Default git reset is of type mixed…
Work directory
Which tree does my command affect?
Index or
Staging area
Local r...
changes
THEORY
Default git reset is a mixed reset…
Work directory
Which tree does my command affect?
Index or
Staging area...
@durdn
Ancestry references
You can specify commits via their ancestry.
The more common examples are
HEAD^ = the parent of ...
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
...
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 conf...
CONFLICT RESOLUTION
Basics for easy conflict resolution
The common commands are:
$ git checkout --ours/--theirs <file>
Che...
CONFLICT RESOLUTION
Aliases for easy conflict resolution
Add these to [alias] in .gitconfig:
ours = "!f() { 

}; f"
git ch...
@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 bd1174cd0f30fe9be9efd...
@durdn
Let’s talk about merge strategies!
git has breadth of choice on how to
merge changes!
recursiveresolve octopus
subt...
@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 ...
@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}
st...
@durdn
Thank you!
NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN
Twitter: @durdn
Upcoming SlideShare
Loading in …5
×

Git Power Routines

Slide counterparts of video course found here: https://www.youtube.com/playlist?list=PLDshL1Z581YYxLsjYwM25HkIYrymXb7H_

Follow along or just sit back and enjoy a live, hands on tutorial on the power routines of experienced git users. We'll explore with real world examples how to amend commits, do an interactive rebase - and why would you want to do one in the first place, how to solve conflicts without any merge tools, the power of less known merge strategies, how to do interactive commits, and much more.

Course notes

Part 1/8: Introduction
Who am I?
Content overview.
Choice of test project.

Part 2/8: Housekeeping
Find my aliases here.
Enhance your shell with liquidprompt.
Start with an empty commit.
Short cuts to list commits with nice annotations:

Part 3/8: Amending and rebasing
Amend a commit.
Reset a commit to perform a rename.
Different resets affect different parts of a git repository.

Part 4/8: Interactive rebase
How to perform an interactive rebase to remove a binary file stuck in the repository

Part 5/8: Solving conflicts
In this 5th part of the course we'll show a few concepts useful when solving merge and rebase conflicts with an interactive example on how to solve one.
We'll explain --ours, --theirs, conflict markers and what's the process needed to solve a conflict using Git.

Part 6/8: What is a merge and alternative merge strategies
We cover the basics of what a merge is in Git and we show the use of a couple of less known merge strategies like the "ours" merge strategy and the "octopus" strategy.

Part 7/8: Git interactive add
In this part we show how to perform and interactive add using Git. That is splitting the contents of some change across to more semantically meaningful commits.

Part 8/8: How to use Git stash
How to use git stash to solve common workflow situations, swap context with ease and smoothness and look cool to your colleagues.

  • Login to see the comments

Git Power Routines

  1. 1. Git Power Routines NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Master the art and practice of DVCS
  2. 2. @durdn REMOVE BINARIES Follow along, solve real world daily version control situations CONFLICT RESOLUTION MERGE STRATEGIES INTERACTIVE COMMITS AMEND AND REBASE
  3. 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
  4. 4. @durdn About the sample project
  5. 5. ADVENTURE AWAITS House keeping [1] Get a nice prompt: Liquid prompt is awesome http://bit.do/liquid-prompt
  6. 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. 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. 8. @durdn Common and not so common un-doings and re-doings Amending and Re-basing
  9. 9. Credit: Emma Jane Hogbin Westby @emmajanehw
  10. 10. Credit: Emma Jane Hogbin Westby @emmajanehw
  11. 11. Obvious!
  12. 12. THEORY Always think of these Work directory Which tree does my command affect? Index or Staging area Local repository (.git) Remotes
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. @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
  17. 17. Now let’s change a commit in the past
  18. 18. @durdn What is a rebase? It’s a way to replay commits, one by one, on top of a branch master feature
  19. 19. @durdn What is an --interactive rebase? Helps you clean up your private branches before publishing them reword fixup pick squash edit exec
  20. 20. For complex history cleanup use git filter-branch or BFG
  21. 21. UNDOINGS BFG Repo-Cleaner is a nice option http://bit.do/bfg
  22. 22. @durdn Let’s learn to solve conflicts Believe me, it can be done without tears and sweat.
  23. 23. 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
  24. 24. 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
  25. 25. CONFLICT RESOLUTION Aliases for easy conflict resolution Add these to [alias] in .gitconfig: ours = "!f() { }; f" git checkout --ours $@ && git add $@;
  26. 26. @durdn Embrace useful merge strategies Merging the right way can go a long way…
  27. 27. @durdn What is a merge? Merge commit master feature merges keep the context of the feature’s commits feature m aster
  28. 28. 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
  29. 29. @durdn Let’s talk about merge strategies! git has breadth of choice on how to merge changes! recursiveresolve octopus subtreeours yours?
  30. 30. @durdn merge strategy: ours master feature Records a merge but skips incoming changes IGNORE!
  31. 31. strategy --ours is useful to promote recent branches to master
  32. 32. @durdn feature What is a fast-forward merge? master It will just shift the HEAD tag feature m aster
  33. 33. @durdn What is a fast-forward merge? master It will just shift the HEAD tag feature m aster
  34. 34. Octopus merge is nice for staging servers.
  35. 35. UNDOINGS Octopus Merge can be very useful http://bit.do/git-octopus
  36. 36. UNDOINGS Octopus Merge can be very useful
  37. 37. @durdn Interactive add (and commit) Splitting commits semantically in flight!
  38. 38. 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
  39. 39. @durdn Switch context at will Git stash power techniques
  40. 40. @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
  41. 41. @durdn
  42. 42. Thank you! NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Twitter: @durdn

×