Working with Git

496 views

Published on

Working with Git – a simple introduction for those used to working with a VCS like Subversion. Explains concepts and shows examples. Feel free to steal slides for your own purposes.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
496
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • I’m not a Git expert, just a happy user for the last three years. Before that, I used Subversion.\n
  • Created in 2005 by Linus Torvalds to work on the Linux kernel\nBuilt around the concepts of distributed version control and non-linear development\n
  • \n
  • What do we mean by “distributed”? Let’s take a look at an example using Subversion.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • Person A makes commits his changes to the Subversion server. Person B updates their working copy from the server.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • In the Git world, there is no central server. Repositories live locally on a person’s hard drive. There are no revision numbers – instead there’s a hash representing each commit. One person can pull from another person’s repository into their own. They don’t need to pull all changes.\n
  • There is no one copy. Different people can merge and track other people’s branches. The result is it’s possible for different development workflows than “one linear log of work.” Having said that...\n
  • ...in most projects, you will have a central, canonical repository, because it’s convenient. But you don’t have to share all your branches and commits with it. [Compare Subversion/trunk Git/master]\n
  • Everything in git is local.\n
  • \n
  • \n
  • Git is a collection of tools. Git works well by itself, but it plays better with friends. It’s designed to work as part of an ecosystem of development. It knows that version control is just a tool, that’s part of your workflow as a developer. It stresses flexibility, speed, and integration with your workflow. [Prune large files, branch/merge speeds, Git hooks as example]\n
  • One of the things you’ll hear quite often. It refers to the method and speed that Git handles branches. When a branch takes a half second to create and incurs no file size penalty, it’s trivial to create them. When you don’t have to share them, you don’t need to worry about making too many branches. It’s also easy to branch from a branch, which is common.\n
  • Simple example workflow. Nothing earth-shattering.\n
  • Meet Bob.\n
  • \n
  • Bob has an ambition.\n
  • He wants to start his own religion.\n
  • The Church of Bob\n
  • \n
  • He starts by writing his holy book. [Explain git init]\nNext: Working copy/staging area\n
  • [Explain concepts]\nLet’s say we change a file...\n
  • \n
  • We use git add to move it into the staging area. \n
  • \n
  • Once in the area [explain about how making changes won’t affect the staging area’s version]\n
  • \n
  • Git commit will save the changes in the staging area along with a commit message.\n
  • \n
  • Let’s go back to Bob, who’s written his first chapter of the Book of Bob.\n
  • He’s saved the file as ‘chapter1.txt’\nNext: git status\n
  • Next: git add\n
  • Next: git commit\n
  • Next: hashes\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Next: Bob makes a friend\n
  • Bob makes a friend...\n
  • Meet Tim.\nNext: create tome of secrets\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Next: branches\n
  • Next: Bob and Tim part ways\n
  • \n
  • As in common in open source...\n
  • \n
  • Next: Using Git\n
  • Next: Using Git\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Working with Git

    1. 1. WORKING WITH GIT Distributed version control and youPete Nicholls @Aupajo github.com/Aupajo
    2. 2. Git
    3. 3. WHY SWITCH?More flexibleBetter toolsBetter workflowMore people are using it
    4. 4. Git is distributed version control.
    5. 5. SUBVERSION
    6. 6. SUBVERSION revision 2revision 2 revision 2
    7. 7. SUBVERSIONCommit! revision 2 revision 2 revision 2
    8. 8. SUBVERSION revision 3revision 3 revision 2
    9. 9. SUBVERSION revision 3revision 3 revision 3
    10. 10. GIT908bc475 be8decb9
    11. 11. GITCommit! 908bc475 be8decb9
    12. 12. GIT72f9b575 be8decb9
    13. 13. GIT Pull!72f9b575 be8decb9
    14. 14. GIT72f9b575 72f9b575
    15. 15. GITThere is no “one copy”...
    16. 16. GIT...but usually you’ll agree on a central repository.
    17. 17. Git is local.
    18. 18. EVERYTHING IS LOCALEverything is stored in a “.git” directory at the root of yourprojectCommits are localBranches are localYou don’t check out the latest revision – you clone thewhole repository
    19. 19. Pros ConsWork offlineCarry your repository on aflash driveWork on experimentalbranches without cluttering A big repository means a largeup other people’s repositories initial downloadShare when you’re readyNo more waiting in lineEasy to set up, no server torun
    20. 20. Git is a collection of tools.
    21. 21. Git has “cheap” branching.
    22. 22. Workflow
    23. 23. Bob
    24. 24. Hello.Bob
    25. 25. Bob
    26. 26. Bob
    27. 27. CHURCH of BOBBob
    28. 28. Down, heathens. CHURCH of BOBBob
    29. 29. $ mkdir holybook$ cd holybook$ git init
    30. 30. Working Copy Staging Area Commit (Your Project) (Preparing the commit)
    31. 31. Working Copy Staging Area Commit (Your Project) (Preparing the commit)
    32. 32. Working Copy Staging Area Commit (Your Project) (Preparing the commit) git add
    33. 33. Working Copy Staging Area Commit (Your Project) (Preparing the commit) git add
    34. 34. Working Copy Staging Area Commit (Your Project) (Preparing the commit)
    35. 35. Working Copy Staging Area Commit (Your Project) (Preparing the commit) git commit
    36. 36. Working Copy Staging Area Commit (Your Project) (Preparing the commit) git commit
    37. 37. Working Copy Staging Area Commit (Your Project) (Preparing the commit) git commit
    38. 38. Working Copy Staging Area Commit (Your Project) (Preparing the commit)
    39. 39. Chapter IGenesisIn the beginning was the word, andthe word was Bob, who accepted allforms of credit card, yea, evenDiscover.# Saved ‘chapter1.txt’
    40. 40. $ git status# On branch master## Initial commit## Untracked files:# (use "git add <file>..." toinclude in what will be committed)## chapter1.txt
    41. 41. $ git add chapter1.txt$ git status# On branch master## Initial commit## Changes to be committed:# (use "git rm --cached <file>..."to unstage)## new file: chapter1.txt#
    42. 42. $ git commit -m “Added the firstchapter.”[master (root-commit) 8621aee] Addedthe first chapter. 1 files changed, 1 insertions(+), 0deletions(-) create mode 100644 chapter1.txt
    43. 43. $ git logcommit f9ac73d56d3852d1878a4d8a2309ecfda4472e84Author: Pete Nicholls <pete@metanation.com>Date: Sat Apr 9 16:31:28 2011 +1200 Added delimiter to points.diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 37d4a59..c442368 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -41,7 +41,7 @@ module ApplicationHelper end def plain_points(points)- "#{points} points"+ "#{number_with_delimiter points} points" end def link_to_with_count(text, link = nil, count = 0, options = {})
    44. 44. $ git logcommit f9ac73d56d3852d1878a4d8a2309ecfda4472e84Author: Pete Nicholls <pete@metanation.com>Date: Sat Apr 9 16:31:28 2011 +1200 Added delimiter to points.diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 37d4a59..c442368 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -41,7 +41,7 @@ module ApplicationHelper end def plain_points(points)- "#{points} points"+ "#{number_with_delimiter points} points" end def link_to_with_count(text, link = nil, count = 0, options = {})
    45. 45. $ git logcommit f9ac73d56d3852d1878a4d8a2309ecfda4472e84Author: Pete Nicholls <pete@metanation.com>Date: Sat Apr 9 16:31:28 2011 +1200 Added delimiter to points.diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 37d4a59..c442368 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -41,7 +41,7 @@ module ApplicationHelper end def plain_points(points)- "#{points} points"+ "#{number_with_delimiter points} points" end def link_to_with_count(text, link = nil, count = 0, options = {})
    46. 46. $ git logcommit f9ac73d56d3852d1878a4d8a2309ecfda4472e84Author: Pete Nicholls <pete@metanation.com>Date: Sat Apr 9 16:31:28 2011 +1200 Added delimiter to points.diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 37d4a59..c442368 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -41,7 +41,7 @@ module ApplicationHelper end def plain_points(points)- "#{points} points"+ "#{number_with_delimiter points} points" end def link_to_with_count(text, link = nil, count = 0, options = {})
    47. 47. $ git logcommit f9ac73d56d3852d1878a4d8a2309ecfda4472e84Author: Pete Nicholls <pete@metanation.com>Date: Sat Apr 9 16:31:28 2011 +1200 Added delimiter to points.diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 37d4a59..c442368 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -41,7 +41,7 @@ module ApplicationHelper end def plain_points(points)- "#{points} points"+ "#{number_with_delimiter points} points" end def link_to_with_count(text, link = nil, count = 0, options = {})
    48. 48. $ git logcommit f9ac73d56d3852d1878a4d8a2309ecfda4472e84Author: Pete Nicholls <pete@metanation.com>Date: Sat Apr 9 16:31:28 2011 +1200 Added delimiter to points.diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex 37d4a59..c442368 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -41,7 +41,7 @@ module ApplicationHelper end def plain_points(points)- "#{points} points"+ "#{number_with_delimiter points} points" end def link_to_with_count(text, link = nil, count = 0, options = {})
    49. 49. Author DateCommit Message Diff
    50. 50. Author Date f9ac73d56d3852d1878...Commit Message Diff
    51. 51. Bob
    52. 52. Bob Tim
    53. 53. Bob Tim
    54. 54. Bob
    55. 55. Tome of SecretsBob
    56. 56. $ git remote add origin git://tomeofsecrets/holybook.git$ git push origin master
    57. 57. $ git clone git://tomeofsecrets/holybook.git$ cd holybook
    58. 58. Chapter IITim the EnchanterBob said unto Tim, “Yea, and we willmake so much money.” And Tim saw thatit was good, or at least better thanhis usual Saturday nights out.# Saved ‘chapter2.txt’
    59. 59. $ git add chapter2.txt$ git commit -m “Added the secondchapter.”$ git push origin master $ git pull origin master $ ls chapter1.txt chapter2.txt
    60. 60. $ git commit -m “Added the bit withthe killer rabbit.”$ git commit -m “Added the bit withthe bridge crossing.”$ git commit -m “Proper coconut use.” $ git commit -m “Added smiting.” $ git commit -m “Turned peasant into a mustard pot.” $ git commit -m “Extra smiting.”
    61. 61. $ git checkout -b commandments$ git branch master* commandments
    62. 62. $ git checkout -b commandments$ git add commandments.txt$ git commit -m “Startedcommandments.”$ ls chapter1.txt chapter2.txt commandments.txt$ git checkout master$ ls chapter1.txt chapter2.txt
    63. 63. $ git checkout commandments$ git commit -m “Thou shalt not standin the doorway to chat, thus blockingother shoppers access to the groceryaisle.”$ git commit -m “Thou shalt thinkgoat horns are cool.”$ git checkout master$ git merge commandments
    64. 64. Branchesmaster mastersmiting commandments master
    65. 65. Branchesmaster mastersmiting commandments master
    66. 66. “Thou shalt not be judged for not showering.”
    67. 67. $ git remote add churchoftim git://churchoftim/holybook.git$ git push churchoftim master
    68. 68. Forkstomeofsecrets churchoftim
    69. 69. Forkstomeofsecrets churchoftim
    70. 70. Using Git
    71. 71. msygitGit for the command-line.http://git-scm.comTortoiseGitFile browser and contextualmenu integration, port ofTortoiseSVN.http://code.google.com/p/tortoisegitCygwinLinux environment forWindows. Git availablethrough package manager.http://cygwin.com
    72. 72. Homebrewbrew install githttps://github.com/mxcl/homebrewMacPortsport install githttp://code.google.com/p/tortoisegitTowerVery polished Git GUI.http://git-tower.com
    73. 73. Towerhttp://git-tower.com
    74. 74. EGithttp://eclipse.org/egit/
    75. 75. GitHubhttp://github.com
    76. 76. Demohttp://github.com

    ×