Getting Started with Git5/17/2012                             This presentation is at:                             http://...
Questions I Plan to AnswerWhat is source control?What is the big deal with Git?Can you show me a little Git?  Commits. Bra...
What is Source Control?A mechanism to track changes in source code.Used for version history, auditing, andrecovery.Source ...
Revision Control Example: Wiki
Revision Control Example: GitThis is what well be trying.
GitGit is an open source, distributed versioncontrol system designed for speed andefficiency.                    ● Freedom...
Installing Git http://git-scm.com/book/en/Getting-Started-Installing-Git           The installation is very easy!
Warning: Command Line Ahead
First Time Use: Set UpTell Git who you are!% git config --global user.name "Rick Umali"% git config --global user.email "r...
Creating a "Repository"Lets pretend were developing a Drupalmodule.%   cd web/sites/all/modules%   mkdir dumpstamp%   cd d...
Committing Your First FileTo commit means to save the state of yourwork. You must first add this change to thestaging area...
Looking at the Repository% git logEach commit contains an ID, along with theauthor information from earlier, and a timesta...
Adding More Files%   vi dumpstamp.info dumpstamp.module%   git status%   git add .%   git commitThis second commit saves t...
Bonus: Creating a Module% drush pm-info dumpstamp% drush enable dumpstamp
Examining Changes to Files%   vi dumpstamp.module%   git status%   git diff%   git add dumpstamp.module%   git commit%   g...
Doing More Changes% vi dumpstamp.module% git diff% git commit -aOr even:% git commit -a -m "Commit message."Another typica...
Looking at the Log AgainThe history can be examined different ways.%   git   log%   git   log --format=short%   git   log ...
Revisiting HistoryYou can revisit any point of your history.% git checkout SHAIDEvery commit is known by its SHA ID.This i...
Branching and Merging Next, But...What we have covered so far is probably 70-    80% of what you will do with git.Adding a...
BranchingGit encourages experimentation, by makingbranching very easy.
Branching: git checkout -b% git checkout -b BRANCH SHA1Make some edits on a change below themaster, then commit.git branch...
Branching: Starting StateNOTE: master is a branch thats created by default.                    master        SHA 1A
Branching: Make Some Changesgit commit             master   SHA 2B                      SHA 1A
Branching: Making a Branchgit checkout -b branch1 SHA1    master        SHA 2B                  SHA 1A           branch1  ...
Branching: Changes on the Branch(Make changes in branch1.)git commit master    SHA 2B        SHA 3C   branch1             ...
Visualizing the Branches
MergingBringing two branches together.Git calculates the correct merge base.First checkout the branch you want to mergeint...
Merging: Starting Stategit branchmaster   SHA 2B        SHA 3C   branch1              SHA 1A
Merging: Two Stepsgit checkout mastergit merge branch1     master            SHA 4D              SHA 2B            SHA 3C ...
Merging: The Hard PartManual merging may be required.
Visualizing the Merge
Whew!
Remote BranchesYou can browse public Git repositories forcode that you want to examine or use.You can upload a local Git r...
Common Public Git Repositories
Browsing and Grabbing Codegit clone git@github.com:rickumali/RickUmaliVanityWebsite.git
Uploading Code (to Github)Create a key pair on your machine.Create a repository (on Github).Add a remote (via git remote a...
Creating a Key Pair
Creating a Repository
Adding a Remote, then Upload
After An Upload (to Github)git clone git@github.com:rickumali/DumpStamp.git
Next StepsInstall Git.Commit your code changes frequently.Log verbosely (in commit messages).Experiment (branch) often.
Resourceshttp://git-scm.org/    Both "Pro Git" book, and Git referencehttp://gitref.org/    A "quicker" Git referencehttp:...
Resourceshttp://www.youtube.com/watch?v=4XpnKHJAok8    Linus Torvalds (Git creator) (May 07)http://www.youtube.com/watch?v...
Getting Started with Git                       Thank you!Rick Umalirickumali@gmail.comhttp://tech.rickumali.com/
Upcoming SlideShare
Loading in …5
×

Getting Started with Git

294 views

Published on

Source code control is the most important practice that a software professional can do. This presentation introduces Git, the modern, distributed, version control designed for speed and efficiency.

This was delivered for a local Drupal user group.

I originally gave this presentation at the Drupal Self-Help Group meetup, in May 2012.

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

  • Be the first to like this

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

No notes for slide

Getting Started with Git

  1. 1. Getting Started with Git5/17/2012 This presentation is at: http://sn.im/startgit If youre on Google Docs, make sure to read the speaker notes for this presentation.Rick Umalirickumali@gmail.comhttp://tech.rickumali.com/
  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?A mechanism to track changes in source code.Used for version history, auditing, andrecovery.Source code control is the most importantpractice a coding professional can do.
  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 http://git-scm.com/book/en/Getting-Started-Installing-Git The installation is very easy!
  8. 8. Warning: Command Line Ahead
  9. 9. First Time Use: Set UpTell Git who you are!% git config --global user.name "Rick Umali"% git config --global user.email "rickumali@gmail.com"Future commits will show this information.% git config --listSee "git config --help" for more configurations.
  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% 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.info 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 two requiredfiles for every Drupal module.
  14. 14. Bonus: Creating a Module% drush pm-info dumpstamp% drush 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 useit.
  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 of git (and any version control system).
  20. 20. BranchingGit encourages experimentation, by makingbranching very easy.
  21. 21. Branching: git checkout -b% git checkout -b BRANCH SHA1Make 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 StateNOTE: master is a branch thats created by default. master SHA 1A
  23. 23. Branching: Make Some Changesgit commit master SHA 2B SHA 1A
  24. 24. Branching: Making a Branchgit checkout -b branch1 SHA1 master SHA 2B SHA 1A branch1 NOTE: This command is a short cut for: git branch branch1 name_of_branch , then git checkout branch1 .
  25. 25. Branching: Changes on the Branch(Make changes in branch1.)git commit master SHA 2B SHA 3C branch1 SHA 1A
  26. 26. Visualizing the Branches
  27. 27. MergingBringing two branches together.Git calculates the correct merge base.First checkout the branch you want to mergeinto (typically master), then merge the branch.% git checkout master% git merge BRANCH
  28. 28. Merging: Starting Stategit branchmaster SHA 2B SHA 3C branch1 SHA 1A
  29. 29. Merging: Two Stepsgit checkout mastergit merge branch1 master SHA 4D SHA 2B SHA 3C branch1 SHA 1A
  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 git@github.com:rickumali/RickUmaliVanityWebsite.git
  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 git@github.com:rickumali/DumpStamp.git
  41. 41. Next StepsInstall Git.Commit your code changes frequently.Log verbosely (in commit messages).Experiment (branch) often.
  42. 42. Resourceshttp://git-scm.org/ Both "Pro Git" book, and Git referencehttp://gitref.org/ A "quicker" Git referencehttp://www-cs-students.stanford.edu/~blynn/gitmagic/ "Friendlier" Git walk-through (git magic).http://drupal.org/node/803746 A workflow for using Git with Drupal.http://www.mail-archive.com/dri-devel@lists.sourceforge.net/msg39091.html Linus on "clean history."
  43. 43. Resourceshttp://www.youtube.com/watch?v=4XpnKHJAok8 Linus Torvalds (Git creator) (May 07)http://www.youtube.com/watch?v=8dhZ9BXQgc4 Randal Schwartz (Perl expert and Git old-timer) (Oct07)http://www.youtube.com/watch?v=ZDR433b0HJY Scott Chacon (Pro Git author) (July 11)
  44. 44. Getting Started with Git Thank you!Rick Umalirickumali@gmail.comhttp://tech.rickumali.com/

×