Getting Into Git
Upcoming SlideShare
Loading in...5

Getting Into Git



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

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



Total Views
Slideshare-icon Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Getting Into Git Getting Into Git Presentation Transcript

    • 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:
    • 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.
    • 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.
    • 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● No "server" required● Unique architecture
    • Installing Git installation is very easy!
    • Warning: Command Line Ahead
    • Our Example: A Basic Drupal Module
    • 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!
    • 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.
    • 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.
    • 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.
    • Enabling Our Drupal Module% drush pm-info dumpstamp% drush pm-enable dumpstamp
    • 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.
    • Doing More Changes% vi dumpstamp.module% git diff% git commit -aOr even:% git commit -a -m "Commit message."Another typical workflow.
    • Looking at the Log AgainThe history can be examined different ways.% git log% git log --format=short% git log --format=oneline% git log --oneline
    • 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.)
    • 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).
    • Git encourages experimentation, by makingbranching very easy.Branching
    • 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).
    • Branching: Starting StateSHA 1AmasterNOTE: master is a branch thats created by default.
    • Branching: Make Some ChangesSHA 1ASHA 2Bmastergit commit
    • Branching: Making a BranchSHA 1ASHA 2Bmasterbranch1git branch "branch1" SHA1Agit checkout "branch1"OR git checkout -b branch1 SHA1A
    • Branching: Changes on the BranchSHA 1ASHA 2Bmaster branch1SHA 3C(Make changes in "branch1".)git commit
    • Visualizing the Branches
    • MergingBringing two branches together.First checkout the branch you want to mergeinto (typically master), then merge thebranch.% git checkout master% git merge BRANCH
    • Merging: Starting StateSHA 1ASHA 2Bmaster branch1SHA 3C
    • Merging: Two StepsSHA 1ASHA 2Bmasterbranch1SHA 3CSHA 4Dgit checkout mastergit merge branch1
    • 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 repository to apublic Git repository.
    • Common Public Git Repositories
    • Browsing and Grabbing Codegit clone
    • 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).
    • Creating a Key Pair
    • Creating a Repository
    • Adding a Remote, then Upload
    • After An Upload (to Github)git clone
    • Next StepsInstall Git.Commit your code changes frequently.Log verbosely (in commit messages).Experiment (branch) often.
    • Getting Into GitRick you!
    • 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."
    • Resources Torvalds (Git creator) (May 07) Schwartz (Perl expert and Git old-timer) (Oct07) Chacon (Pro Git author) (July 11)