Getting Into Git


Published on

This was a presentation I gave at the 2012 NorthEast PHP conference, in Cambridge, MA.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Getting Into Git

  1. 1. Getting Into Git8/11/2012Rick presentation is on Google Drive at: you can read the speaker notes for thispresentation. You can also provide feedback at:
  2. 2. Questions I Plan to AnswerWhat is source control?What is the big deal with Git?Can you show me a little Git?Commits. Branches. Merges. Remote repos.
  3. 3. What is Source Control?Source code control is the most importantpractice a coding professional can do.A mechanism to track changes in source code.Used for version history, auditing, andrecovery.
  4. 4. Revision Control Example: Wiki
  5. 5. Revision Control Example: GitThis is what well be trying.
  6. 6. GitGit is an open source, distributed versioncontrol system designed for speed andefficiency.● Freedom● No "server" required● Unique architecture
  7. 7. Installing Git installation is very easy!
  8. 8. Warning: Command Line Ahead
  9. 9. Our Example: A Basic Drupal Module
  10. 10. Creating a "Repository"Lets pretend were developing a Drupalmodule.% cd web/sites/all/modules% mkdir dumpstamp% cd dumpstamp% git init"git init" creates the entire Git repository. Noserver interaction required!
  11. 11. Committing Your First FileTo commit means to save the state of yourwork. You must first add this change to thestaging area.% vi README.txt% git add README.txt% git commit -m "First commit. README file."Use git help to learn all the switches. -mstands for message.
  12. 12. Looking at the Repository History% git logEach commit contains an ID, along with theauthor information from earlier, and a timestamp.% gitkGUI tools can help you visualize the repo.
  13. 13. Adding More Files% vi dumpstamp.module% git status% git add .% git commitThis second commit saves the work of addingtwo files by using git add ..The .module and .info files are the tworequired files for every Drupal module.
  14. 14. Enabling Our Drupal Module% drush pm-info dumpstamp% drush pm-enable dumpstamp
  15. 15. Examining Changes to Files% vi dumpstamp.module% git status% git diff% git add dumpstamp.module% git commit% git logThe above is a typical workflow.Git offers suggestions and hints as you use it.
  16. 16. Doing More Changes% vi dumpstamp.module% git diff% git commit -aOr even:% git commit -a -m "Commit message."Another typical workflow.
  17. 17. Looking at the Log AgainThe history can be examined different ways.% git log% git log --format=short% git log --format=oneline% git log --oneline
  18. 18. Revisiting HistoryYou can revisit any point of your history.% git checkout SHAIDEvery commit is known by its SHA ID.This is the first step in making a branch! (Usegit checkout master to revert.)
  19. 19. Branching and Merging Next, But...What we have covered so far is probably 70-80% of what you will do with git.Adding and committing files are the heart ofgit (and any version control system).
  20. 20. Git encourages experimentation, by makingbranching very easy.Branching
  21. 21. Branching: git branch% git branch BRANCH SHA1% git checkout BRANCHMake some edits on a change below themaster, then commit.git branch makes a branch from the branchyoure on (default branch is master).
  22. 22. Branching: Starting StateSHA 1AmasterNOTE: master is a branch thats created by default.
  23. 23. Branching: Make Some ChangesSHA 1ASHA 2Bmastergit commit
  24. 24. Branching: Making a BranchSHA 1ASHA 2Bmasterbranch1git branch "branch1" SHA1Agit checkout "branch1"OR git checkout -b branch1 SHA1A
  25. 25. Branching: Changes on the BranchSHA 1ASHA 2Bmaster branch1SHA 3C(Make changes in "branch1".)git commit
  26. 26. Visualizing the Branches
  27. 27. MergingBringing two branches together.First checkout the branch you want to mergeinto (typically master), then merge thebranch.% git checkout master% git merge BRANCH
  28. 28. Merging: Starting StateSHA 1ASHA 2Bmaster branch1SHA 3C
  29. 29. Merging: Two StepsSHA 1ASHA 2Bmasterbranch1SHA 3CSHA 4Dgit checkout mastergit merge branch1
  30. 30. Merging: The Hard PartManual merging may be required.
  31. 31. Visualizing the Merge
  32. 32. Whew!
  33. 33. Remote BranchesYou can browse public Git repositories forcode that you want to examine or use.You can upload a local Git repository to apublic Git repository.
  34. 34. Common Public Git Repositories
  35. 35. Browsing and Grabbing Codegit clone
  36. 36. Uploading Code (to Github)Create a key pair on your machine.Create a repository (on Github).Add a remote (via git remote add).Upload your code (via git push).
  37. 37. Creating a Key Pair
  38. 38. Creating a Repository
  39. 39. Adding a Remote, then Upload
  40. 40. After An Upload (to Github)git clone
  41. 41. Next StepsInstall Git.Commit your code changes frequently.Log verbosely (in commit messages).Experiment (branch) often.
  42. 42. Getting Into GitRick you!
  43. 43. Resources "Pro Git" book, and Git reference "quicker" Git reference"Friendlier" Git walk-through (git magic). workflow for using Git with Drupal. on "clean history."
  44. 44. Resources Torvalds (Git creator) (May 07) Schwartz (Perl expert and Git old-timer) (Oct07) Chacon (Pro Git author) (July 11)