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.

Power routines of experienced Git users

1,614 views

Published on

This is the deck part of a 1,5 hours workshop delivered at AtlasCamp 2015.

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 do an interactive rebase - and why would you want to do one in the first place, how to solve conflicts without any merge tools, stashing tricks, the power of less known merge strategies and much more.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Power routines of experienced Git users

  1. 1. Master the art and practice of DVCS NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Power routines of experienced Git users
  2. 2. 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. 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. 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. THEORY Always think of these Work directory Which tree does my command affect? Index or Staging area Local repository (.git) Remotes
  12. 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. 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. 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. 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. 16. Now let’s change a commit in the past
  17. 17. What is a rebase? It’s a way to replay commits, one by one, on top of a branch master feature
  18. 18. What is an --interactive rebase? Helps you clean up your private branches before publishing them reword fixup pick squash edit exec
  19. 19. For complex history cleanup use git filter-branch or BFG
  20. 20. UNDOINGS BFG Repo-Cleaner is a nice option http://bit.do/bfg
  21. 21. Let’s learn to solve conflicts Believe me, it can be done without tears and sweat.
  22. 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. 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. 24. CONFLICT RESOLUTION Aliases for easy conflict resolution Add these to [alias] in .gitconfig: ours = "!f() { }; f" git checkout --ours $@ && git add $@;
  25. 25. Embrace useful merge strategies Merging the right way can go a long way…
  26. 26. What is a merge? Merge commit master feature merges keep the context of the feature’s commits feature m aster
  27. 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. 28. Let’s talk about merge strategies! git has breadth of choice on how to merge changes! recursiveresolve octopus subtreeours yours?
  29. 29. merge strategy: ours master feature Records a merge but skips incoming changes IGNORE!
  30. 30. strategy --ours is useful to promote recent branches to master
  31. 31. feature What is a fast-forward merge? master It will just shift the HEAD tag feature m aster
  32. 32. What is a fast-forward merge? master It will just shift the HEAD tag feature m aster
  33. 33. Octopus merge is nice for staging servers.
  34. 34. UNDOINGS Octopus Merge can be very useful http://bit.do/git-octopus
  35. 35. UNDOINGS Octopus Merge can be very useful
  36. 36. Interactive add (and commit) Splitting commits semantically in flight!
  37. 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. 38. Switch context at will Git stash power techniques
  39. 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. 40. Thank you! NICOLA PAOLUCCI • DEVELOPER INSTIGATOR • ATLASSIAN • @DURDN Twitter: @durdn

×