$30 off During Our Annual Pro Sale. View Details »

Introduction to VCS and Git

Introduction to VCS and Git

Alexey Buzdin

October 14, 2015
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. Introduction to VCS

  2. @AlexeyBuzdin Developer / Trainer at

  3. How to work in a team?

  4. Solutions? • FTP server • Dropbox • USB drive

  5. What do we need? • “Checkout-Change-Commit” approach • Disable concurrent

    changes • Changes history
  6. Version Control System • Tool for managing a *collection of

    files and its content. • *Collection is called a Repository
  7. When to VCS? • Almost every time you write code!

    • Great even for a single file
  8. Dvcs vs Cvcs master repo all repo are equal

  9. Dvcs vs Cvcs master repo all repo are equal

  10. Popularity in OS Eclipse Community Survey

  11. None
  12. Merge Conflicts

  13. Git Essentials

  14. Git is a DVCS • Everything is done locally (check

    in / commit / branch / merge) • Collaboration via repository sync • Peer to Peer approach (all repo are equal) • Stores history locally (Distributed Version Control System)
  15. Pros and Cons • Fast revision checkout • Offline usage

    • Local commits • Full control over VCS • Binary snapshot history • Repos can be heavy on first checkout due to local history • Hard to master
  16. Install Git • http://git-scm.com/ • http://www.sourcetreeapp.com/ Git itself: GUI app:

  17. Configure Git Credentials: • git config —global user.name alexey.buzdin •

    git config —global user.email alex.buzdin@gmail.com ~/.gitconfig - global REPO/.git/config - local
  18. [merge] tool = p4merge keepBackup = false [mergetool "p4merge"] cmd

    = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" keepTemporaries = false trustExitCode = false keepBackup = false prompt = false [difftool] external = p4diff [push] default = current [credential] helper = osxkeychain [branch] autosetuprebase = always [user] name = alexey.buzdin email = alex.buzdin@gmail.com [mergetool] keepBackup = false prompt = false [alias] st = status [core] autocrlf = input excludesfile = /Users/alexeybuzdin/.gitignore_global [difftool "sourcetree"] cmd = opendiff \"$LOCAL\" \"$REMOTE\" path = [mergetool "sourcetree"] cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merg \"$MERGED\" trustExitCode = true vim ~/.gitconfig
  19. .gitignore # NuGet dependencies packages/ # Android module specifics **/Resource.designer.cs

    # Shared files **/bin/ **/obj/ *_ReSharper.*/ # Misc files *.user *.suo *.userprefs *.DS_Store *.swp # Migration .svn
  20. New Git Project • mkdir git-introduction; cd git-introduction • git

    init • git remote add origin https://github.com/LArchaon/learning-git-repo.git • git fetch • git checkout master
  21. New Git Project • mkdir git-introduction; cd git-introduction • git

    init • git remote add origin https://github.com/LArchaon/learning-git-repo.git • git fetch • git checkout master or • git clone https://github.com/LArchaon/learning-git-repo.git
  22. Git help • git help • git <command> --help

  23. Git lifecycle

  24. Example • echo "Hello World" > a.txt • git status

    • git add a.txt • git status • git commit -m ”Initial commit” • git status • ???
  25. Git lifecycle git add <filename> git add <filename> git commit

    git rm —cached <filename>
  26. Commit

  27. Branching

  28. Branching @

  29. Navigation • git checkout 98ca9 • git checkout master •

    git checkout v1.0 • git checkout @ or git checkout HEAD
  30. Branching • git branch newBranch • git checkout newBranch or

    • git checkout -b newBranch
  31. Branching

  32. Branching

  33. Branching

  34. Merge

  35. Merge • git checkout master • git merge iss53 •

    enter commit message “C5”
  36. Merge

  37. Merging Pros • Simple to use and understand. • Maintains

    the original context of the source branch. • The commits on the source branch remain separate from other branch commits. This separation can be useful in the case of feature branches, where you might want to take a feature and merge it into another branch later. • Existing commits on the source branch are unchanged and remain valid; it doesn’t matter if they’ve been shared with others.
  38. Merging Cons • If the need to merge arises simply

    because multiple people are working on the same branch in parallel, the merges don’t serve any useful historic purpose and create clutter.
  39. Rebase

  40. if Merge done

  41. if Rebase done • git checkout experiment • git rebase

    master
  42. then • git checkout master • git merge experiment

  43. Rebase Pros • Simplifies your history. • Is the most

    intuitive and clutter-free way to combine commits from multiple developers in a shared branch
  44. Rebase Cons • Slightly more complex, especially under conflict conditions.

    Each commit is rebased in order, and a conflict will interrupt the process of rebasing multiple commits. With a conflict, you have to resolve the conflict in order to continue the rebase. • Rewriting of history has ramifications if you’ve previously pushed those commits elsewhere.
  45. Lets get hardcore! • git rebase --onto master server client

  46. more!!! “Check out the client branch, figure out the patches

    from the common ancestor of the client and server branches, and then replay them onto master.”
  47. then • git checkout master • git merge client

  48. morrreee…. • git rebase master server

  49. Success! • git checkout master • git merge server •

    git branch -d client • git branch -d server
  50. You feeling?

  51. • …. • git commit -m ”My commit” • git

    pull • git push
  52. Git pull • git pull = git fetch + git

    merge <remote>/branch
  53. Merge bubble • git pull = git fetch + git

    merge <remote>/branch
  54. • …. • git commit -m ”My commit” • git

    stash • git pull --rebase • git push • git stash apply
  55. Clean and pretty

  56. • git pull —rebase • git push

  57. • git pull —rebase int-mng master • git push int-mng

    master
  58. None
  59. None
  60. None
  61. http://git-scm.com/book/

  62. None
  63. None
  64. Countries Chapters Events 106 601 3222

  65. gdgriga.lv

  66. None
  67. https://developers.google.com/groups/ Find us at

  68. May 28 - 29, 2015 https://events.google.com/io2015/

  69. May 28 - 29, 2015 https://www.youtube.com/watch?v=ksvdvCDO7pA

  70. Q&A Thank You!