Git session Dropsolid.com

  • 213 views
Uploaded on

Git session

Git session

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
213
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
4
Comments
1
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Git session Hannes Tack
  • 2. Overview 1. What is git? 2. Basic git 3. Workflow 4. Tips and tricks
  • 3. What is git?
  • 4. What is git? Open source distributed version control system
  • 5. Distributed • Everything is local – Fast – Every clone is a backup – Work offline
  • 6. Basic git
  • 7. Installing Git • Download from http://gitscm.com/downloads • Launch the installer • Or Xcode, homebrew, …
  • 8. Configuring Git • $ git config --global user.name 'Hannes Tack‟ • $ git config –global user.email „hannes@dropsolid.com‟
  • 9. Clone a repo
  • 10. Clone a repo • Clone an existing repo or create a new one: – $ git clone user@host:repo
  • 11. .gitignore
  • 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. .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. 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. 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. A Basic Workflow
  • 17. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  • 18. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  • 19. A basic workflow
  • 20. A basic workflow Git diff • Git diff shows what you‟ve changed • $ git diff <filename>
  • 21. A basic workflow
  • 22. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  • 23. A basic workflow
  • 24. A basic workflow
  • 25. A basic workflow
  • 26. A basic workflow
  • 27. A basic workflow
  • 28. Git add
  • 29. A basic workflow
  • 30. A basic workflow
  • 31. A basic workflow
  • 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. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  • 34. Git commit
  • 35. A basic workflow
  • 36. A basic workflow
  • 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. A basic workflow • • • • • Write code Stage your changes Review your changes Commit your changes Push your changes
  • 39. Git push
  • 40. A basic workflow
  • 41. A basic workflow
  • 42. A basic workflow
  • 43. Merging
  • 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. A basic workflow Git pull
  • 46. A basic workflow Git push
  • 47. A basic workflow Git pull
  • 48. A basic workflow Git pull
  • 49. A basic workflow Git pull
  • 50. A basic workflow Git pull
  • 51. A basic workflow Git pull
  • 52. A basic workflow Git pull
  • 53. A basic workflow Fix code manually
  • 54. A basic workflow Fix conflict UI
  • 55. A basic workflow Fix conflict UI
  • 56. A basic workflow Push merged code
  • 57. Git log
  • 58. Git log - View the latest 10 log messages - $ git log -n 10
  • 59. Git log - Show nicer log: - $ git log --oneline -n 20
  • 60. Git log - Search log messages content: $ git log --grep=Breadcrumb
  • 61. Git log - Search log messages content: $ git log --grep=Breadcrumb
  • 62. Git log - Search commit content: $ git log -S "Implements hook_views_data" –oneline
  • 63. Git log - Show commit content:
$ git show de25c94
  • 64. Undoing things
  • 65. Git checkout
  • 66. Git checkout
  • 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. Git checkout
  • 69. Git reset
  • 70. Git reset
  • 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. Git reset
  • 73. Git reset --hard
  • 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. Git revert
  • 76. Git revert • Undo a specific commit:
$ git revert 5497461 • Creates a new commit that removes the specified commit.
  • 77. Git revert
  • 78. Branching
  • 79. Branching - List local branches: $ git branch
  • 80. Branching - List all branches:
$ git branch -a
  • 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. Branching - Use a remote branch:
$ git checkout -t origin/issue-11699
  • 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. Tagging
  • 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. 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. Patching
  • 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. Tips & tricks
  • 90. Git stash
  • 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. Git stash • Apply a stash:
$ git stash apply stash@{0}
  • 93. Git stash
  • 94. Git aliases
  • 95. Git bisect • Shortcuts • Define aliases in .gitconfig file. • Ex: ~/.gitconfig
  • 96. Git aliases
  • 97. Git aliases
  • 98. Git bisect
  • 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. 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. Resources
  • 102. Resources • Pro git book: http://git-scm.com/book • Git bisect tutorial: http://webchick.net/node/99
  • 103. Questions?