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.

Everything you ever wanted to know about Git (But were afraid to ask)

2,686 views

Published on

**NOTE: This slide deck contains many animations. You should download and view in PowerPoint if you can! ***

Git (and GitHub) have become pillars in how we manage our code workflow, particularly when we work with large teams. Yet developers tend to be afraid of Git, and only handle but the most basic of operations. This presentation will reveal the magic of Git, and help you understand how and why operations are carried out.

After this session, you'll never be afraid of a merge conflict again.
Topics covered: * Git under the hood * Git basics * Merging vs Rebasing * Conflict resolution * Triangular Workflow * Common error scenarios and how to solve them * Tips and Tricks

Published in: Technology
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • slide 7, download link is for git-completion.bash and not git-prompt.sh
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Excellent at presentation at SV Code Camp, thank you. Should write a book..
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Everything you ever wanted to know about Git (But were afraid to ask)

  1. 1. Everything you wanted to know about GIT (BUT WERE AFRAID TO ASK)
  2. 2. ANIMATIONS AHEAD!!! This deck has plenty of animations to explain some concepts. Please view in presentation mode
  3. 3. Setting up  Apple GIT gotchas: Xcode ships with its custom version of git. You don’t want this: $ git --version git version 2.3.2 (Apple Git-55) $ which git /usr/bin/git
  4. 4. Setting Up  The right git: Download and install: http://git-scm.com/download/mac Set up: Modify ~/.profile export PATH=/usr/local/bin:$PATH $ git --version git version 2.4.3
  5. 5. Setting Up  Make life easy for yourself: Autocomplete! Download: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash Save to -> ~/.git-completion.bash (Note the dot!) Add to ~/.profile # Run git autocomplete source ~/.git-completion.bash Verify -> git check<tab> --autocompletes to--> git checkout PRO TIP: Also autocompletes branch names!
  6. 6. Setting Up  Make life easy for yourself, PART 2: Change your terminal prompt! Download: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh Save to -> ~/.git-prompt.sh (Note the dot!) Add to ~/.profile # Run git prompt enhancements source ~/.git-prompt.sh export GIT_PS1_SHOWDIRTYSTATE=true export GIT_PS1_SHOWUNTRACKEDFILES=true export GIT_PS1_SHOWCOLORHINTS=true export PROMPT_COMMAND='__git_ps1 "w" "$ "'
  7. 7. GIT Init GIT IS MISUNDERSTOOD. IT JUST WANTS TO BE YOUR FRIEND
  8. 8. Git isn’t magic. BLOBS TREES COMMITS
  9. 9. Git tracks everything. Forever!  Files (Blobs) are tracked based on content, not on their name.  Git uses the SHA1 algorithm to create a unique hash (fingerprint) for each file. foo.txt -> “Hello” -> e965047ad7c57865823c7d992b1d046ea66edf78
  10. 10. How is it calculated? “blob”+space Do it yourself! printf ”blob 6000Hellon" | shasum Null char Length of content File content b l o b 6 0 0 0 H e l l o n
  11. 11. All versions of a file end up as blobs. E9650 Hello 980a0 Hello World! 53627 Hello World! How are you? 7a27f Hello World! How are you today? 557db Hello World
  12. 12. Trees organize (and name) sets of files E9650 Hello a69b2 557db Hello World 8984f
  13. 13. Commit ec445 Commit bd297 Commits give order to trees E9650 Hello Tree: a69b2 Author: lmarkus Message: First Commit 557db Hello World bd297ec445 Tree: 8984f Parent: ec445 Author: lmarkus Message: Second Commit
  14. 14. Git Recap  Git saves *everything*  Git keeps track of what your project looked like at a given time (tree + commit)  Git keeps a history of the various snapshots as a linked list. (commit -> parent)
  15. 15. The world is my stage!
  16. 16. The world is my stage! HEAD STAGE Work Dir
  17. 17. The world is my stage! HEAD STAGE Work Dir $ git status On branch master nothing to commit, working directory clean
  18. 18. The world is my stage! HEAD STAGE Work Dir
  19. 19. The world is my stage! HEAD STAGE Work Dir $ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: miner.txt no changes added to commit (use "git add" and/or "git commit -a")
  20. 20. The world is my stage! HEAD STAGE Work Dir $ git add miner.txt
  21. 21. The world is my stage! HEAD STAGE Work Dir
  22. 22. The world is my stage! HEAD STAGE Work Dir $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: miner.txt
  23. 23. The world is my stage! HEAD STAGE Work Dir
  24. 24. The world is my stage! HEAD STAGE Work Dir
  25. 25. The world is my stage! HEAD STAGE Work Dir $ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: miner.txt Untracked files: (use "git add <file>..." to include in what will be committed) sun.txt
  26. 26. The world is my stage! HEAD STAGE Work Dir $ git commit -m “Mining is hard”
  27. 27. The world is my stage! HEAD STAGE Work Dir
  28. 28. “Oops…” moments
  29. 29. Git Reset A B C D E STAGE WORKING DIR E E HEAD
  30. 30. Git Reset --soft A B C D E STAGE WORKING DIR E E HEADgit reset --soft HEAD~1
  31. 31. Git Reset --mixed A B C D E STAGE WORKING DIR D E HEADgit reset --mixed HEAD~1 E
  32. 32. Git Reset --hard A B C D E STAGE WORKING DIR D D HEADgit reset --hard HEAD~1 E E
  33. 33. Clean up after yourself!
  34. 34. Git Rebase - Part I A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting.
  35. 35. Git Rebase - Part I A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. $ git log --oneline 845c2a5 Actually, that wasn't a bug. Reverting 10ae9b3 Oops, fixed a bug 5c68b04 Fixed Another typo 83775b2 Fixed Typo 099d98e Created New Function
  36. 36. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. $ git rebase -i HEAD~4 pick 83775b2 Fixed Typo pick 5c68b04 Fixed Another typo pick 10ae9b3 Oops, fixed a bug pick 845c2a5 Actually, that wasn't a bug. Reverting # Rebase 099d98e..845c2a5 onto 099d98e (4 command(s)) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # These lines can be re-ordered; they are executed from top to bottom. # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. # Note that empty commits are commented out
  37. 37. A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. pick 83775b2 Fixed Typo pick 5c68b04 Fixed Another typo pick 10ae9b3 Oops, fixed a bug pick 845c2a5 Actually, that wasn't a bug. Reverting squash Git rebase --interactive
  38. 38. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. pick 83775b2 Fixed Typo squash 5c68b04 Fixed Another typo
  39. 39. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. pick 83775b2 Fixed Typo squash 5c68b04 Fixed Another typo
  40. 40. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. # This is a combination of 2 commits. # The first commit's message is: Fixed Typo # This is the 2nd commit message: Fixed Another typo # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit.
  41. 41. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. # This is a combination of 2 commits. # The first commit's message is: Documentation updates # This is the 2nd commit message: # Fixed Another typo # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit.
  42. 42. Git rebase --interactive A B C D E Created New Function Fixed typo Fixed Another typo Oops! Fixed a bug. Actually, that wasn’t a bug. Reverting. $ git log --oneline 779dbd5 Documentation updates 099d98e Created New Function
  43. 43. Branching out
  44. 44. Branches A B C MASTER  Remember: Your git history is just a linked list of commits.  A branch simply represents a marker somewhere in this history. It points to the latest commit within a set.
  45. 45. Branches A B C MASTER DEVELOP git checkout -b develop
  46. 46. Branches A B C MASTER D E DEVELOP git commit -m ”D” git commit -m ”E”
  47. 47. Branches A B C MASTER D E DEVELOP git checkout master
  48. 48. Branches A B C MASTER D E DEVELOP git commit -m “F” F
  49. 49. Rebase Vs Merge A B C MASTER D E DEVELOP F
  50. 50. Merge A B C MASTER D E DEVELOP F M Merge commits have TWO parents. They represent the point where to branches became one git merge develop X Y Work can continue after a merge
  51. 51. Rebase A B C D E DEVELOP MASTER F We just re-wrote history! git rebase develop
  52. 52. Rebase Vs Merge - RECAP A B C MASTER D E DEVELOP F M X Y A B C MASTER D* E* F Merge  Very explicit, accurate history  Visually complex  Easy to roll back Rebase  Linear history  Easy to understand  Not historically accurate  Hard to undo.
  53. 53. Playing well with others
  54. 54. Forking and Cloning Develop Release Master Develop Release Master */Customers-R/activation * = http://github.paypal.com */lmarkus/activation Develop Release Master originupstream
  55. 55. Forking and Cloning Develop Release Master lmarkus/activation Develop Release Master origin Develop Release Master Customers-R/activation upstream person1/activation person2/activation person3/activation
  56. 56. Forking and Cloning UPSTREAM ORIGIN LOCAL git remote update git rebase upstream/develop git push origin develop DEVELOP BRANCH
  57. 57. Forking and Cloning - Common Error #1 UPSTREAM ORIGIN LOCAL git push origin develop DEVELOP BRANCH git remote update git rebase upstream/develop git push origin develop
  58. 58. Forking and Cloning - Common Error #1 $ git push origin develop To https://github.paypal.com/lmarkus/activation.git ! [rejected] develop -> develop (non-fast-forward) error: failed to push some refs to https://github.paypal.com/lmarkus/activation.git hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  59. 59. Forking and Cloning - Common Error #1 UPSTREAM ORIGIN LOCAL DEVELOP BRANCH Option 1: git pull origin develop git push origin master Solves the problem, but history gets messy. Doubled up commits
  60. 60. Forking and Cloning - Common Error #1 UPSTREAM ORIGIN LOCAL DEVELOP BRANCH Option 2: git push origin master --force The Force has a dark side… You are overwriting history which may be shared
  61. 61. Resolving merge conflicts
  62. 62. What happens during a merge Animals.txt Animals I like: Dogs! Animals.txt Animals I like: Cats! Birds! master feature1 git merge feature1 Animals.txt Animals I like: <<<<<<< HEAD Dogs! ======= Cats! Birds! >>>>>>> feature1
  63. 63. What happens during a merge Animals.txt Animals I like: Dogs! Animals.txt Animals I like: Cats! Birds! master feature1 Animals.txt Animals I like: <<<<<<< HEAD Dogs! ======= Cats! Birds! >>>>>>> feature1 git add Animals.txt git commit -m “Dogs Rule”
  64. 64. Resolve conflicts the smart way!
  65. 65. Resolve conflicts the smart way! Shortcuts!
  66. 66. Resolve conflicts the smart way!

×