use git the proper way                      or How I learned to stop worrying and love rebase             Jaime Buelta
BASIC CONCEPTS
INDEX         LOCAL REPOSITORY                    (staging area)       (HEAD) WORKPATHThe files in your    What you are    ...
COMMIT TREE
different names for a commit                    HEAD                               master                   HEAD^SHA1: 01d...
Version control systemsare communication tools They DONT replace ALL communication  (just make it easier)
BUSINESS AS USUAL
BASIC LOCAL WORKFLOWgit add (append to index)git rm (append removal of file to index)git checkout file (retrieve file from in...
WORKING WITH THE STASHgit stash (push your workpath to the stash)git stash pop (retrieve last changes on stash)git stash l...
COMMIT STRATEGIEScommit small, commit ofteneach commit should be an atomicrelated change of the codeadd reference numberdo...
MEASURE TWICE, CUT ONCEgit status (show index and workpath status)git log [–graph] (show commit log)graphical tools to sho...
USE A DIFFTOOL
DIFF AND DIFFTOOLgit diff                   git diff id                             diff between workpath  diff between wo...
REMOTE REPOSITORYgit fetch (get changes from remote repo)git pull (get remote branch and apply on top of local)git push (t...
MERGE VS REBASE                                  develop                                        new_feature               ...
WORKING WITH BRANCHESgit checkout branch (change to local branch)git checkout -b branch (create new branch)git branch –tra...
NOT ALL BRANCHES ARE    CREATED EQUALLocal branches (so be careful when pushing changes)Feature/experimental branch (that ...
BRANCH STRATEGIESWhen working on a feature, merge back often toavoid big discrepancies with main branchIn general, try to ...
RECOVERING THE PASTgit checkout id (change to id commit)git checkout id -- file                   (change only file to id co...
WHEN SOMETHING GOES WRONG        (AND YOU KNOW WHAT IT IS)Try not to push your error to the repositorygit commit --amend (...
WHEN SOMETHING GOES WRONG           (MERGE CONFLICTS)Use a mergetool!Double-Check before committingMerging often avoid lon...
WHEN SOMETHING GOES WRONG  ON A REBASE/MERGE/PULL       (AND YOU KNOW WHAT IT IS)git reflog (show branch tag in previous co...
UNDO A REBASE                    new_feature  master                           ORIG_HEAD           rebasegit reset –hard O...
TOO LATE, I PUSHED MY          CHANGES...git revert commit (new commit undoing specified commit)
WHEN SOMETHING GOES WRONG(AND YOU HAVE NO CLUE ABOUT WHAT IT IS)  git blame file (show each line with writer and SHA)  git ...
SOME CONFIGURATION         OPTIONSCOLORS!  git config color.ui truessh keys to repo  No more typing passwordsmerge tool and...
RESOURCESGit doc (same as man files) http://www.kernel.org/pub/software/scm/git/docs/Pro git http://progit.org/book/ (lot a...
QUESTIONS?   Thanks for your      attention                @jaimebuelta  wrongsideofmemphis.worspress.com
Use git the proper way
Upcoming SlideShare
Loading in...5
×

Use git the proper way

3,435

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,435
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
45
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Not a fan of gui tools for everything, though\n
  • Very useful also for merges\n
  • \n
  • \n
  • \n
  • \n
  • For pointer branches, ideally, should be merged back immediately when a hot fix arrises\n
  • \n
  • \n
  • When something goes wrong\n
  • \n
  • Run tests, if possible\n
  • Reflog shows the pointers to the branches, etc on the last actions. Good for bad rebases/merges/pull\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Use git the proper way

    1. 1. use git the proper way or How I learned to stop worrying and love rebase Jaime Buelta
    2. 2. BASIC CONCEPTS
    3. 3. INDEX LOCAL REPOSITORY (staging area) (HEAD) WORKPATHThe files in your What you are Tracked by git hard drive going to commit
    4. 4. COMMIT TREE
    5. 5. different names for a commit HEAD master HEAD^SHA1: 01d1d5ac9bc28e10902f99a15f9fd979d449adb2 b12 origin/HEAD origin/master
    6. 6. Version control systemsare communication tools They DONT replace ALL communication (just make it easier)
    7. 7. BUSINESS AS USUAL
    8. 8. BASIC LOCAL WORKFLOWgit add (append to index)git rm (append removal of file to index)git checkout file (retrieve file from index)git reset HEAD file (remove from index)
    9. 9. WORKING WITH THE STASHgit stash (push your workpath to the stash)git stash pop (retrieve last changes on stash)git stash list (list all changes on stash)git stash drop (remove last changes on stash)
    10. 10. COMMIT STRATEGIEScommit small, commit ofteneach commit should be an atomicrelated change of the codeadd reference numberdouble check before committing
    11. 11. MEASURE TWICE, CUT ONCEgit status (show index and workpath status)git log [–graph] (show commit log)graphical tools to show log gitg (Linux), gitx (Mac), tig (Command line), gitk, SourceTree git gui (can add individual lines to the index)
    12. 12. USE A DIFFTOOL
    13. 13. DIFF AND DIFFTOOLgit diff git diff id diff between workpath diff between workpath and id and index git diff id id2git diff -- file diff between id1 and id2 diff one filegit diff --cached diff between index and HEAD
    14. 14. REMOTE REPOSITORYgit fetch (get changes from remote repo)git pull (get remote branch and apply on top of local)git push (try to apply local changes to remote repo)git pull = fetch + mergegit pull --rebase = fetch + rebase
    15. 15. MERGE VS REBASE develop new_feature new_feature new_featuredevelop develop merge rebase
    16. 16. WORKING WITH BRANCHESgit checkout branch (change to local branch)git checkout -b branch (create new branch)git branch –track branch origin/branch (track remote branch)git merge branch (merge branch into current branch)git rebase branch (rebase current branch on top o of branch)
    17. 17. NOT ALL BRANCHES ARE CREATED EQUALLocal branches (so be careful when pushing changes)Feature/experimental branch (that should be merged back to the main branch)“Pointer” branch (a particular previous commit of permanent branch, like master)Main, permanent branch (develop/master)
    18. 18. BRANCH STRATEGIESWhen working on a feature, merge back often toavoid big discrepancies with main branchIn general, try to use rebase instead of mergeIf hotfixing, use cherry-pick to keep main branch up-to-dateLimit the number of branches
    19. 19. RECOVERING THE PASTgit checkout id (change to id commit)git checkout id -- file (change only file to id commit)
    20. 20. WHEN SOMETHING GOES WRONG (AND YOU KNOW WHAT IT IS)Try not to push your error to the repositorygit commit --amend (fix your last commit)git reset (change your index/HEAD) git reset –soft (dont change your workspace) git reset –hard (change your workspace)
    21. 21. WHEN SOMETHING GOES WRONG (MERGE CONFLICTS)Use a mergetool!Double-Check before committingMerging often avoid long and difficult mergeconflicts
    22. 22. WHEN SOMETHING GOES WRONG ON A REBASE/MERGE/PULL (AND YOU KNOW WHAT IT IS)git reflog (show branch tag in previous commands)
    23. 23. UNDO A REBASE new_feature master ORIG_HEAD rebasegit reset –hard ORIG_HEAD
    24. 24. TOO LATE, I PUSHED MY CHANGES...git revert commit (new commit undoing specified commit)
    25. 25. WHEN SOMETHING GOES WRONG(AND YOU HAVE NO CLUE ABOUT WHAT IT IS) git blame file (show each line with writer and SHA) git grep pattern (search pattern in git-tracked files) git log -Spattern (pickaxe - search commits that change pattern) gitk file (show commits related to file) git bisect (walk through commits to find which one introduces a bug)
    26. 26. SOME CONFIGURATION OPTIONSCOLORS! git config color.ui truessh keys to repo No more typing passwordsmerge tool and difftoolautocorrect git config help.autocorrect 2 (0.2 sec)
    27. 27. RESOURCESGit doc (same as man files) http://www.kernel.org/pub/software/scm/git/docs/Pro git http://progit.org/book/ (lot about the internals)Git community book http://book.git-scm.com/Cheat sheet http://ndpsoftware.com/git-cheatsheet.htmlStackOverflow http://stackoverflow.com/
    28. 28. QUESTIONS? Thanks for your attention @jaimebuelta wrongsideofmemphis.worspress.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×