getting started with git
DESCRIPTION
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.TRANSCRIPT
![Page 1: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/1.jpg)
Getting Started with Git5/17/2012
Rick [email protected]://tech.rickumali.com/
This presentation is at:
http://sn.im/startgit
If you're on Google Docs, make sure to read the 'speaker notes' for this presentation.
![Page 2: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/2.jpg)
Questions I Plan to Answer
What is source control?
What is the big deal with Git?
Can you show me a little Git?Commits. Branches. Merges. Remote repos.
![Page 3: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/3.jpg)
What is Source Control?
A mechanism to track changes in source code.
Used for version history, auditing, and recovery.
Source code control is the most important practice a coding professional can do.
![Page 4: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/4.jpg)
Revision Control Example: Wiki
![Page 5: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/5.jpg)
Revision Control Example: Git
This is what we'll be trying.
![Page 6: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/6.jpg)
Git
Git is an open source, distributed version control system designed for speed and efficiency.
● Freedom● No "server" required● Unique architecture
![Page 7: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/7.jpg)
Installing Git
http://git-scm.com/book/en/Getting-Started-Installing-Git
The installation is very easy!
![Page 8: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/8.jpg)
Warning: Command Line Ahead
![Page 9: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/9.jpg)
First Time Use: Set Up
Tell Git who you are!
% git config --global user.name "Rick Umali"% git config --global user.email "[email protected]"
Future 'commits' will show this information.
% git config --list
See "git config --help" for more configurations.
![Page 10: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/10.jpg)
Creating a "Repository"
Let's pretend we're developing a Drupal module.
% cd web/sites/all/modules% mkdir dumpstamp% cd dumpstamp% git init
"git init" creates the entire Git repository. No server interaction required!
![Page 11: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/11.jpg)
Committing Your First File
To 'commit' means 'to save the state' of your work. You must first 'add' this change to the 'staging area'.
% vi README.txt% git add README.txt% git commit -m "First commit. README file."
Use 'git help' to learn all the switches. -m stands for message.
![Page 12: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/12.jpg)
Looking at the Repository
% git log
Each 'commit' contains an ID, along with the author information from earlier, and a time stamp.
% gitk
GUI tools can help you visualize the 'repo.'
![Page 13: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/13.jpg)
Adding More Files% vi dumpstamp.info dumpstamp.module% git status% git add .% git commit
This second commit saves the work of adding two files by using 'git add .'.
The .module and .info files are the two required files for every Drupal module.
![Page 14: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/14.jpg)
Bonus: Creating a Module% drush pm-info dumpstamp
% drush enable dumpstamp
![Page 15: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/15.jpg)
Examining Changes to Files% vi dumpstamp.module% git status% git diff% git add dumpstamp.module% git commit% git log
The above is a typical 'workflow'.
Git offers suggestions and hints as you use it.
![Page 16: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/16.jpg)
Doing More Changes% vi dumpstamp.module% git diff% git commit -a
Or even:
% git commit -a -m "Commit message."
Another typical 'workflow'.
![Page 17: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/17.jpg)
Looking at the Log Again
The history can be examined different ways.
% git log% git log --format=short% git log --format=oneline% git log --oneline
![Page 18: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/18.jpg)
Revisiting History
You can 'revisit' any point of your history.
% git checkout SHAID
Every commit is known by its SHA ID.
This is the first step in making a branch! (Use git checkout master to revert.)
![Page 19: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/19.jpg)
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).
![Page 20: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/20.jpg)
Git encourages experimentation, by making branching very easy.
Branching
![Page 21: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/21.jpg)
Branching: git checkout -b
% git checkout -b BRANCH SHA1
Make some edits on a change below the master, then commit.
git branch makes a branch from the branch you're on (default branch is 'master').
![Page 22: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/22.jpg)
Branching: Starting State
SHA 1Amaster
NOTE: 'master' is a branch that's created 'by default'.
![Page 23: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/23.jpg)
Branching: Make Some Changes
SHA 1A
SHA 2Bmaster
git commit
![Page 24: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/24.jpg)
Branching: Making a Branch
SHA 1A
SHA 2Bmaster
branch1
git checkout -b branch1 SHA1
NOTE: This command is a short cut for: git branch branch1 name_of_branch , then git checkout branch1 .
![Page 25: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/25.jpg)
Branching: Changes on the Branch
SHA 1A
SHA 2Bmaster branch1SHA 3C
(Make changes in branch1.)git commit
![Page 26: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/26.jpg)
Visualizing the Branches
![Page 27: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/27.jpg)
Merging
Bringing two branches together.
Git calculates the correct 'merge base'.
First 'checkout' the branch you want to merge into (typically master), then 'merge' the branch.
% git checkout master% git merge BRANCH
![Page 28: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/28.jpg)
Merging: Starting State
SHA 1A
SHA 2Bmaster branch1SHA 3C
git branch
![Page 29: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/29.jpg)
Merging: Two Steps
SHA 1A
SHA 2B
master
branch1SHA 3C
SHA 4D
git checkout mastergit merge branch1
![Page 30: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/30.jpg)
Merging: The Hard Part
Manual 'merging' may be required.
![Page 31: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/31.jpg)
Visualizing the Merge
![Page 32: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/32.jpg)
Whew!
![Page 33: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/33.jpg)
Remote Branches
You can 'browse' public Git repositories for code that you want to examine or use.
You can upload a local Git repository to a public Git repository.
![Page 34: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/34.jpg)
Common Public Git Repositories
![Page 36: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/36.jpg)
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).
![Page 37: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/37.jpg)
Creating a Key Pair
![Page 38: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/38.jpg)
Creating a Repository
![Page 39: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/39.jpg)
Adding a Remote, then Upload
![Page 41: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/41.jpg)
Next Steps
Install Git.
Commit your code changes frequently.
Log verbosely (in commit messages).
Experiment (branch) often.
![Page 42: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/42.jpg)
Resources
http://git-scm.org/Both "Pro Git" book, and Git reference
http://gitref.org/A "quicker" Git reference
http://www-cs-students.stanford.edu/~blynn/gitmagic/"Friendlier" Git walk-through (git magic).
http://drupal.org/node/803746A workflow for using Git with Drupal.
http://www.mail-archive.com/[email protected]/msg39091.html
Linus on "clean history."
![Page 43: Getting Started with Git](https://reader034.vdocuments.us/reader034/viewer/2022051312/547b9b93b37959652b8b4db6/html5/thumbnails/43.jpg)
Resources
http://www.youtube.com/watch?v=4XpnKHJAok8Linus Torvalds (Git creator) (May '07)
http://www.youtube.com/watch?v=8dhZ9BXQgc4Randal Schwartz (Perl expert and Git old-timer) (Oct
'07)http://www.youtube.com/watch?v=ZDR433b0HJY
Scott Chacon (Pro Git author) (July '11)