Gittalk

797 views

Published on

  • Be the first to comment

  • Be the first to like this

Gittalk

  1. 1. Git and Github Basics http://git-scm.com
  2. 2. Why Git?
  3. 3. Why Git?Distributed Repositories
  4. 4. Why Git?Distributed RepositoriesEasy Merging
  5. 5. Why Git?Distributed RepositoriesEasy MergingNo File Locks
  6. 6. Starting From Scratch?
  7. 7. Starting From Scratch?new_project patrick$ git initInitialized empty Git repository in /Users/patrick/gittalk/new_project/.git/
  8. 8. Existing Repository?
  9. 9. Existing Repository?patrick$ git clone git@github.com:thelearninghouse/request-forms.git <location>
  10. 10. Committing a changepatrick$ echo "Initial README" > READMEpatrick$ git add READMEpatrick$ git commit -m "Added README"[master (root-commit) 5008efe] Added README 1 file changed, 1 insertion(+) create mode 100644 README
  11. 11. What Happened?
  12. 12. What Happened?patrick$ git logcommit 5008efe3eab3e746f1d54214566c6b3ed79d3656Author: Patrick Tinsley <prtinsley@gmail.com>Date: Thu Oct 25 21:31:17 2012 -0400 Added README
  13. 13. How Git Works Working Directory git add Staging git commit Repository
  14. 14. WorkflowCodeStage your changes (git add)Review your work (git status, git diff)Commit (locally) (git commit)Repeat
  15. 15. Un-Staged Changes
  16. 16. Un-Staged Changespatrick$ echo “I’m updating this again.” > README
  17. 17. Un-Staged Changespatrick$ echo “I’m updating this again.” > READMEpatrick$ 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 inworking directory)## modified: README#no changes added to commit (use "git add" and/or "git commit -a")
  18. 18. Staged Changes
  19. 19. Staged Changespatrick$ git add .
  20. 20. Staged Changespatrick$ git add .patrick$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: README#
  21. 21. Reset
  22. 22. Resetpatrick$ git resetUnstaged changes after reset:M README
  23. 23. Resetpatrick$ git resetUnstaged changes after reset:M READMEpatrick$ 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 workingdirectory)## modified: README#no changes added to commit (use "git add" and/or "git commit -a")
  24. 24. Hard Reset
  25. 25. Hard Resetpatrick$ git reset --hard HEADHEAD is now at e502220 Test update
  26. 26. Why Branch?
  27. 27. Why Branch?Safely experiment with new ideas
  28. 28. Why Branch?Safely experiment with new ideasAgility
  29. 29. Why Branch?Safely experiment with new ideasAgilityGit makes branching easy
  30. 30. Why Branch?Safely experiment with new ideasAgilityGit makes branching easyGit makes merging (usually...) very easy
  31. 31. Branch and Mergec5 c4 c3 c2 c1 master c2 c1 new_feature
  32. 32. How Do We Do It?
  33. 33. How Do We Do It?patrick$ git checkout -b new_featureSwitched to a new branch new_feature
  34. 34. How Do We Do It?patrick$ git checkout -b new_featureSwitched to a new branch new_featurepatrick$ git branch master* new_feature
  35. 35. How Do We Do It?patrick$ git checkout -b new_featureSwitched to a new branch new_featurepatrick$ git branch master* new_featurepatrick$ git checkout masterSwitched to branch master
  36. 36. How Do We Do It?patrick$ git checkout -b new_featureSwitched to a new branch new_featurepatrick$ git branch master* new_featurepatrick$ git checkout masterSwitched to branch masterpatrick$ git branch -d new_featureDeleted branch new_feature (was5008efe).
  37. 37. What About Merging?
  38. 38. What About Merging?patrick$ git checkout masterSwitched to branch master
  39. 39. What About Merging?patrick$ git checkout masterSwitched to branch masterpatrick$ git merge update_readmeUpdating 01ba47f..ee04cb3Fast-forward README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
  40. 40. Conflict!
  41. 41. Conflict!patrick$ git merge update_readmeAuto-merging READMECONFLICT (content): Merge conflict in READMEAutomatic merge failed; fix conflicts and then commit the result.
  42. 42. What Happened?
  43. 43. What Happened?patrick$ git status# On branch master# Unmerged paths:# (use "git add/rm <file>..." as appropriate to markresolution)## both modified: README#no changes added to commit (use "git add" and/or "git commit -a")
  44. 44. Resolve and Commit
  45. 45. Remote RepositoriesGithub.comAnother copy, much like yoursBackupCollaborateDistributeService Hooks
  46. 46. Working With Github
  47. 47. Working With GithubUpdate your knowledge of Github (git fetch)
  48. 48. Working With GithubUpdate your knowledge of Github (git fetch)Update your local copy (git pull)
  49. 49. Working With GithubUpdate your knowledge of Github (git fetch)Update your local copy (git pull)Push your code to Github (git push)
  50. 50. Example
  51. 51. Exampleexample_app patrick$ git pull origin masterFrom github.com:prtinsley/example_app * branch master -> FETCH_HEADAlready up-to-date.
  52. 52. Exampleexample_app patrick$ git pull origin masterFrom github.com:prtinsley/example_app * branch master -> FETCH_HEADAlready up-to-date.example_app patrick$ git push origin masterCounting objects: 5, done.Delta compression using up to 8 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 300 bytes, done.Total 3 (delta 2), reused 0 (delta 0)To git@github.com:prtinsley/first_app.git 261f716..8b66dca master -> master
  53. 53. Stashing
  54. 54. StashingCannot change branches with pendingchangesSave your work if not ready to commitApply pending changes to a different branchWorks like a stack
  55. 55. Example
  56. 56. Examplepatrick$ 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 workingdirectory)## modified: README
  57. 57. Examplepatrick$ 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 workingdirectory)## modified: READMEpatrick$ git stashSaved working directory and index state WIP on master: 92a5183Updated READMEHEAD is now at 92a5183 Updated README
  58. 58. Example
  59. 59. Examplepatrick$ git status# On branch masternothing to commit (working directory clean)
  60. 60. Examplepatrick$ git status# On branch masternothing to commit (working directory clean)patrick$ git stash apply# 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 inworking directory)## modified: README#
  61. 61. DeploymentsCode pulled from repository or build archiveCode not checked in will be overwrittenSoon all production servers will be IT accessonly
  62. 62. Resourceshttp://help.github.comhttp://git-scm.com/book Definitive guide written by a Github devhttp://net.tutsplus.com/tutorials/other/easy-version-control-with-git/ Much more basic
  63. 63. GUI ClientsTower http://www.git-tower.com/SourceTree http://www.sourcetreeapp.com/Github for Mac http://mac.github.com/
  64. 64. Questions?
  65. 65. Githubhttp://github.com
  66. 66. Context
  67. 67. Activity Feed
  68. 68. Main Repository Page
  69. 69. Clone URL
  70. 70. Branches
  71. 71. Commit History
  72. 72. Commit History
  73. 73. Change Sets
  74. 74. Excellent Help Docshttp://help.git.com
  75. 75. Questions?
  76. 76. Slides Available

×