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.

Git and github - Verson Control for the Modern Developer

1,161 views

Published on

An introduction to Git and Github, tools for distributed version control that give an easy to use and highly collaborative approach to version code and configuration.

Published in: Software
  • Be the first to comment

Git and github - Verson Control for the Modern Developer

  1. 1. Git & Github - version control for the modern developer by John Stevenson @jr0cket git.practical.li
  2. 2. Why Git / Version control Helping us manage and collaborate
  3. 3. We learn from history, so don't delete it Those who cannot remember the past are condemned to repeat it - George Santayana
  4. 4. History at your fingertips git log --oneline --decorate
  5. 5. Version control should be easy Every developer should be able to manage changes without a dedicated version control team - makes developers more likely to version their software more often - smaller commits - meaningful commit messages - easy merging of changes - easy to experiment & throw away code
  6. 6. What is Git... it's not just me when I am being grumpy...
  7. 7. Distributed vs Centralised model
  8. 8. Distributed vs Centralised model Centralised - only 1 server, single version of the truth - typically a locking approach - requires central server setup - single point of failure in central server - only use when connected to the network Distributed - only requires git init to start versioning - have the whole project to work with - multiple repositories give redundancy - commit changes offline & fast - easy to share changes & collaborate - need to decide canonical source of truth
  9. 9. Distributed model in action
  10. 10. Getting Started with Git... it's not just me when I am being grumpy...
  11. 11. Install a Git Client Install your prefered Git Client git-scm.com/downloads/guis
  12. 12. Identifying yourself with Git Labels every commit you make with your identity git config --global user.name “John Stevenson” git config --global user.email “john@jr0cket.co.uk” Git graphical clients also allow you to set your identity and usually save this into your ~/.gitconf file
  13. 13. Tools to Git choose your tools and learn them well...
  14. 14. - Windows & MacOSX desktop.github.com
  15. 15. Emacs Magit - very powerful & easy to use
  16. 16. SourceTree - Atlassian
  17. 17. GitKraken.com
  18. 18. Git Command Line
  19. 19. Git local workflow version your changes locally, before sharing them
  20. 20. Create a local repository: git init Edit your source code (working copy) Add changes you want to capture in the next commit git add filename or file pattern See what files you have changed / added git status Compare changes in working copy git diff filename git diff --cached filename
  21. 21. Create a commit from the added files: git commit -m “meaningful message” See the current history of commits git log --oneline --decorate See the contents of a commit git show commit-number Dont delete the .git directory or you loose all the history of the project
  22. 22. Git Visual Cheatsheet ndpsoftware.com/git-cheatsheet.html
  23. 23. Collaborating with Github additional services around Git
  24. 24. What is Github Github is a cloud service for managing & sharing changes - provides private & public repositories - repository forks & pull requests - collaborative code review - Gists for single file sharing Github pages website publishing - markdown driven content
  25. 25. Authentication methods - SSH Keys vs Passwords SSH authentication - uses a public/private key to authenticate, so no passwords - keys needs to be added to each computer you use Password authentication - account can be cached to minimise typing of credentials
  26. 26. Creating a repository
  27. 27. Cloning a Github Repository Clone (copy completely) an existing repository, giving an optional directory name git clone URL directory-name
  28. 28. Forking a Github Repository You can fork to your account or any Github Organisation you belong too
  29. 29. Submit a pull request
  30. 30. Github Pull Request - Accepted & Merged
  31. 31. Github Pull Request - Code Review
  32. 32. Visualising Github - ghv.artzub.com
  33. 33. Branching & Merging branches should allow experimentation, merging should be simple
  34. 34. Branching Branches allow you to work on - specific features - bug fixes - ideas / experiments Branches can - merged into another branch - have commits cherry picked - be discarded easily - be attached to another branch or be stand alone (eg. gh-pages)
  35. 35. Creating a branch git branch branch-name ;; create a branch attached to the current branch git checkout branch-name ;; checkout branch so new commits are added to it git checkout -b branch-name ;; both commands above in one command git branch ;; lists all branches Creating a stand alone (orphan) branch git branch -o branch-name ;; branch independent of others & shares no history
  36. 36. Branching - discarding Branches can live forever, the longer they live become harder to merge git branch -d branch-name If this branch is also on a remote git repository, you need to push this change git push remote branch-name Or simply delete a branch reference on the remote git repository git push remote --delete branch-name
  37. 37. Merging Checkout branch to receive the merge commits git checkout master git merge feature
  38. 38. Rebasing - only with consent! Note: Anything that affects the history should be done with consent, especially once commits are shared Checkout branch to receive the merge commits git checkout feature git rebase master
  39. 39. Cherry Picking Checkout branch to receive the cherry picked commit git checkout master git cherry-pick commit-number
  40. 40. Deploying with Git Git can be an important part of your release management
  41. 41. Example: Heroku git push heroku master
  42. 42. Example: Heroku git push heroku master
  43. 43. Learning Git in-depth we learn by example...
  44. 44. Books on Git progit.org gitforteams.com
  45. 45. atlassian.com/git/tutorials
  46. 46. Take your own journey into Git
  47. 47. Thank you @jr0cket jr0cket.co.uk

×