Beginner's Guide to Version Control with Git

5,223 views

Published on

Published in: Technology, Business
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,223
On SlideShare
0
From Embeds
0
Number of Embeds
64
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide
  • Hello, my name is Robert Lee-Cann and I’m a web developer.
    In this talk I’ll be introducing you to the basic concepts of version control - what it is, how it works and the benefits it will bring to your development workflow.
  • Hello, my name is Robert Lee-Cann and I’m a web developer.
    In this talk I’ll be introducing you to the basic concepts of version control - what it is, how it works and the benefits it will bring to your development workflow.
  • So what exactly IS version control?
  • So what exactly IS version control?
  • So what exactly IS version control?
  • Beginner's Guide to Version Control with Git

    1. 1. G it’s the way to do it!
    2. 2. G it’s the way to do it! A Beginnerʼs Guide to Version Control with Git.
    3. 3. What is Version Control?
    4. 4. What is Version Control? • Allows you to keep a history of every change within a project.
    5. 5. What is Version Control? • Allows you to keep a history of every change within a project. • Allows multiple people to collaborate on the same project, without evil stuff happening.
    6. 6. What is Version Control? • Allows you to keep a history of every change within a project. • Allows multiple people to collaborate on the same project, without evil stuff happening. • All files (and historical versions) are backed- up automatically.
    7. 7. What is Git?
    8. 8. What is Git? • Created by Linus Torvalds.
    9. 9. What is Git? • Created by Linus Torvalds. • Run locally, with no server needed.
    10. 10. What is Git? • Created by Linus Torvalds. • Run locally, with no server needed. • Works offline.
    11. 11. What is Git? • Created by Linus Torvalds. • Run locally, with no server needed. • Works offline. • Command-line or GUI.
    12. 12. Installation
    13. 13. Installation • Windows: http://code.google.com/p/msysgit/ • Mac OSX: http://code.google.com/p/git-osx-installer/ • Linux: Packages available for most distros, or build from source.
    14. 14. Configuring Git • Configure your name and email address. git config --global user.name = ‘leeky’ git config --global user.email = ‘leeky@leeky.org.uk’ • Using ‘--global’ makes these the default value for all projects.
    15. 15. Starting a New Git-Managed Project
    16. 16. Starting a New Git-Managed Project • Create directory for project.
    17. 17. Starting a New Git-Managed Project • Create directory for project. • cd into project directory.
    18. 18. Starting a New Git-Managed Project • Create directory for project. • cd into project directory. • Type git init to initialise Git for this project.
    19. 19. Starting a New Git-Managed Project • Create directory for project. • cd into project directory. • Type git init to initialise Git for this project. Initialized empty Git repository in /git/demo/.git/
    20. 20. Terminology • Repository - where the current and historical file data is stored. • Working copy - the local copy of files from a repository, at a specific time or revision. • Commit - copy files from your working copy to the repository.These changes are stored together as an individual revision.
    21. 21. Basic Git Workflow 1. Add, edit and delete files in your project in the normal way, using your favourite editor (e.g. TextMate,Vi, Dreamweaver etc). 2. Tell Git which file(s) are to be saved into the new commit using git add 3. Commit files to repository using git commit.
    22. 22. Demo
    23. 23. Git Commands • git status - View status of working copy. • git add - Add unstaged changes. - git add {filename} {filename} ... - git add . • git commit - Commit changes to repository. - git commit -m “{message}”
    24. 24. More Git Commands • git diff- Shows differences between working copy and last revision. • git log - Shows the history log. - git log {filename} - Restrict log to file(s) • git blame {filename} - Shows when/who made changes to a file.
    25. 25. Git GUI • Launch by running git gui in your project’s directory. • Gives you ability to add files and create commits without using the command line!
    26. 26. Gitk • Launch by running gitk in your project’s directory. • Allows you to browse the entire history of your project and see when and by whom files were changed.
    27. 27. Gitk • Launch by running gitk in your project’s directory. • Allows you to browse the entire history of your project and see when and by whom files were changed.
    28. 28. TextMate
    29. 29. TextMate Git Bundle ProjectPlus http://www.gitorious.org/ http://www.ciaranwal.sh/ projects/git-tmbundle 2008/08/05/textmate-plug-in- projectplus
    30. 30. Branching
    31. 31. Branching • Allows experimental features to be developed separately, without affecting stable code.
    32. 32. Branching • Allows experimental features to be developed separately, without affecting stable code. • Branches can be easily created and later merged together.
    33. 33. Branching • Allows experimental features to be developed separately, without affecting stable code. • Branches can be easily created and later merged together. Master Master
    34. 34. Branching • Allows experimental features to be developed separately, without affecting stable code. • Branches can be easily created and later merged together. Master Master git branch Branch Branch
    35. 35. Branching • Allows experimental features to be developed separately, without affecting stable code. • Branches can be easily created and later merged together. Master Master Master Master git branch Branch Branch
    36. 36. Branching • Allows experimental features to be developed separately, without affecting stable code. • Branches can be easily created and later merged together. Master Master Master Master Master git branch Branch Branch git merge
    37. 37. Working with Branches
    38. 38. Working with Branches • git branch - git branch - View branches. - git branch {branchname} - Create a new branch.
    39. 39. Working with Branches • git branch - git branch - View branches. - git branch {branchname} - Create a new branch. • git checkout {branchname} - Switch to another branch.
    40. 40. Working with Branches • git branch - git branch - View branches. - git branch {branchname} - Create a new branch. • git checkout {branchname} - Switch to another branch. • git checkout -b {branchname} - Create new branch and immediately switch to it.
    41. 41. Merging Branches
    42. 42. Merging Branches Merge otherbranch into mainbranch:
    43. 43. Merging Branches Merge otherbranch into mainbranch: • git checkout {mainbranch}
    44. 44. Merging Branches Merge otherbranch into mainbranch: • git checkout {mainbranch} • git merge {otherbranch}
    45. 45. Merging Branches Merge otherbranch into mainbranch: • git checkout {mainbranch} • git merge {otherbranch} • git merge {otherbranch} -m “commit msg”
    46. 46. Conflict Resolution
    47. 47. Conflict Resolution CONFLICT (add/add): Merge conflict in foo Automatic merge failed; fix conflicts and then commit the result.
    48. 48. Conflict Resolution D O N ʼT CONFLICT (add/add): Merge conflict in foo IC ! Automatic merge failed; fix conflicts and then commit the result. N PA
    49. 49. Conflict Resolution # On branch master # Your branch and 'origin/master' have diverged, # and have 1 and 1 different commit(s) each, respectively. # # Changed but not updated: # (use "git add <file>..." to update what will be committed) # # unmerged: foo # no changes added to commit (use "git add" and/or "git commit -a")
    50. 50. Conflict Resolution la la la <<<<<<< HEAD:foo wish dog cow cat ======= moo cow fish >>>>>>> 0cb13d1ceabf7e579b423815d8314fca0475ab7f:foo
    51. 51. Conflict Resolution • Merge manually. • Commit the merge.
    52. 52. Collaborating with Others
    53. 53. Collaborating with Others Clone an existing repository: • git clone {anotherpath} {directory} • git clone {url} {directory} Manage connections to remote repositories: • git remote - git remote add {name} {url}
    54. 54. Pushing & Pulling
    55. 55. Pushing & Pulling Pull (download) from another repository: • git pull {remotename} {remotebranch} • git pull
    56. 56. Pushing & Pulling Pull (download) from another repository: • git pull {remotename} {remotebranch} • git pull Push (upload) to another repository: • git push {remotename} {remotebranch} • git push
    57. 57. Third-party Git Hosts • GitHub - http://www.github.com • Gitorious - http://www.gitorious.org/ • Unfuddle - http://www.unfuddle.com
    58. 58. GitHub Demo
    59. 59. Resources • Git for Designers - http://hoth.entp.com/output/git_for_designers.html • Peepcode Screencast ($9) - https://peepcode.com/products/git • Hosting your own repositories - http://scie.nti.st/2007/11/14/hosting-git- repositories-the-easy-and-secure-way
    60. 60. Thanks for listening. Robert Lee-Cann Lee-Cann Creative hello@lee-cann.com

    ×