Git session Dropsolid.com

709 views

Published on

Git session

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
709
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
14
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Git session Dropsolid.com

  1. 1. Git session Hannes Tack
  2. 2. Overview 1. What is git? 2. Basic git 3. Workflow 4. Tips and tricks
  3. 3. What is git?
  4. 4. What is git? Open source distributed version control system
  5. 5. Distributed • Everything is local – Fast – Every clone is a backup – Work offline
  6. 6. Basic git
  7. 7. Installing Git • Download from http://gitscm.com/downloads • Launch the installer • Or Xcode, homebrew, …
  8. 8. Configuring Git • $ git config --global user.name 'Hannes Tack‟ • $ git config –global user.email „hannes@dropsolid.com‟
  9. 9. Clone a repo
  10. 10. Clone a repo • Clone an existing repo or create a new one: – $ git clone user@host:repo
  11. 11. .gitignore
  12. 12. .gitignore • What? – Makes git ignore files / directories – Repo specific or global – Drupal example of a .gitignore file: http://drupalcode.org/project/drupal.git/blob/HEAD: /example.gitignore
  13. 13. .gitignore # Ignore configuration files that may contain sensitive information */sites/*/settings*.php # Ignore paths that contain user-generated content. */sites/*files */sites/*/private # Ignore editor specific files Drupal.sublime-projectcompletions *.sublime-project *.sublime-workspace # Ignore OS specific files .DS_Store
  14. 14. global .gitignore • Create any file: - $vi ~/.gitignore_global • Add paths to be ignored. - Example: https://gist.github.com/4321950 • Use as global gitignore file: Git config –global core.excludesfile ~/.gitignore_global
  15. 15. local .gitignore • Create a .gitignore file: - $vi ~/your_project/.gitignore • Place it anywhere in your repo • Add paths to be ignored, relative to the location of the file.
  16. 16. A Basic Workflow
  17. 17. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  18. 18. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  19. 19. A basic workflow
  20. 20. A basic workflow Git diff • Git diff shows what you‟ve changed • $ git diff <filename>
  21. 21. A basic workflow
  22. 22. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  23. 23. A basic workflow
  24. 24. A basic workflow
  25. 25. A basic workflow
  26. 26. A basic workflow
  27. 27. A basic workflow
  28. 28. Git add
  29. 29. A basic workflow
  30. 30. A basic workflow
  31. 31. A basic workflow
  32. 32. A basic workflow Staged files • git diff --staged shows the changes that are staged • git reset HEAD <filename> removes a file from “staging”
  33. 33. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  34. 34. Git commit
  35. 35. A basic workflow
  36. 36. A basic workflow
  37. 37. A basic workflow Git commit • Changes are committed to local repo • Others won‟t see these changes yet • Commit message is required • And should look like „Issue #123: describe what you changed.‟
  38. 38. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  39. 39. Git push
  40. 40. A basic workflow
  41. 41. A basic workflow
  42. 42. A basic workflow
  43. 43. Merging
  44. 44. A basic workflow • Remote branch contains commit(s) that are not present in your local branch. • Get those commits first by merging, then push your commits.
  45. 45. A basic workflow Git pull
  46. 46. A basic workflow Git push
  47. 47. A basic workflow Git pull
  48. 48. A basic workflow Git pull
  49. 49. A basic workflow Git pull
  50. 50. A basic workflow Git pull
  51. 51. A basic workflow Git pull
  52. 52. A basic workflow Git pull
  53. 53. A basic workflow Fix code manually
  54. 54. A basic workflow Fix conflict UI
  55. 55. A basic workflow Fix conflict UI
  56. 56. A basic workflow Push merged code
  57. 57. Git log
  58. 58. Git log - View the latest 10 log messages - $ git log -n 10
  59. 59. Git log - Show nicer log: - $ git log --oneline -n 20
  60. 60. Git log - Search log messages content: $ git log --grep=Breadcrumb
  61. 61. Git log - Search log messages content: $ git log --grep=Breadcrumb
  62. 62. Git log - Search commit content: $ git log -S "Implements hook_views_data" –oneline
  63. 63. Git log - Show commit content:
$ git show de25c94
  64. 64. Undoing things
  65. 65. Git checkout
  66. 66. Git checkout
  67. 67. Git checkout • Throw away changes:
$ git checkout index.html • Restores your working tree to the last version committed to git. • Use git checkout to throw away changes that have not been added and committed. • Use carefully.
  68. 68. Git checkout
  69. 69. Git reset
  70. 70. Git reset
  71. 71. Git reset • Keep your code changes, remove file from the index:
$ git reset HEAD index.html • Restores your index to the last version known to git.
  72. 72. Git reset
  73. 73. Git reset --hard
  74. 74. Git reset --hard • Resets working tree and index to a specific commit. • $ git reset --hard 5497461 • Reset a branch to the origin branch:
$ git reset --hard origin/master • Use carefully.
  75. 75. Git revert
  76. 76. Git revert • Undo a specific commit:
$ git revert 5497461 • Creates a new commit that removes the specified commit.
  77. 77. Git revert
  78. 78. Branching
  79. 79. Branching - List local branches: $ git branch
  80. 80. Branching - List all branches:
$ git branch -a
  81. 81. Branching - Create a new branch:
$ git branch issue-123 - Switch to that branch:
$ git checkout issue123 - Or create and switch to a branch:
$ git checkout -b issue-123 - Push branch to origin:
$ git push origin issue-123
  82. 82. Branching - Use a remote branch:
$ git checkout -t origin/issue-11699
  83. 83. Branching • Delete a local branch that is fully merged:
$ git branch -d branch_name • Force delete a local branch:
$ git branch -D branch_name • Delete a remote branch:
$ git push origin -delete :branch_name • Completely remove a branch:
$ git push origin --delete :branch_name
$ git branch -D branch_name
  84. 84. Tagging
  85. 85. Tagging • Create tag:
$ git tag sporting-beta-1 -a -m 'Sporting beta 1 release.' • Push tag:
$ git push --tags • List tags:
$ git tag
  86. 86. Tagging • Move a tag:
$ git tag -f sporting-beta-1 • Delete a tag:
$ git tag -d sporting-beta-1
$ git push origin :sporting-beta-1
  87. 87. Patching
  88. 88. Patching • $ git diff > [project_name][short_description]-[issue-number][comment-number].patch • Add the patch file to the root of the module you patched.
  89. 89. Tips & tricks
  90. 90. Git stash
  91. 91. Git stash • Store code changes without committing them. • Handy when you urgently need to switch branches. • Stash your code changes:
$ git stash • List all available stashes:
$ git stash list • Most recent stash is shown on top
  92. 92. Git stash • Apply a stash:
$ git stash apply stash@{0}
  93. 93. Git stash
  94. 94. Git aliases
  95. 95. Git bisect • Shortcuts • Define aliases in .gitconfig file. • Ex: ~/.gitconfig
  96. 96. Git aliases
  97. 97. Git aliases
  98. 98. Git bisect
  99. 99. Git bisect • Find out in when something broke • First, find a commit when everything was working • Find a commit where things are not working. • Go to the root of the repository • $ git bisect start
$ git bisect good fd0a623
$ git bisect bad 256d85
  100. 100. Git bisect • Refresh the page and see if the bug is there • $ git bisect good/git bisect bad • Repeat until git tells you the commit that broke it
  101. 101. Resources
  102. 102. Resources • Pro git book: http://git-scm.com/book • Git bisect tutorial: http://webchick.net/node/99
  103. 103. Questions?

×