git with the program: introduction to basic git concepts - drupal camp la 2013

42
GIT WITH THE PROGRAM Drupal Camp LA 2013 Matthew Wrather Wrather Creative

Upload: mwrather

Post on 16-May-2015

351 views

Category:

Technology


1 download

DESCRIPTION

Aside from being the version control system that powers Drupal development, Git is the VCS of choice for most modern software development, at least on the web -- as well as a must-have skill for any Drupal developer seeing a job. (Lack of experience with Git is my number one frustration with developers I work with.) But because of its distributed nature (i.e., every copy of the repository is complete unto itself and doesn't necessarily need an authoritative central system), Git presents conceptual challenges not only to beginners but to developers experienced with older forms of version control -- RCS, CVS, SVN, etc. In this session, we'll look at the basic concepts behind Git, including: Why I need version control even if I work alone in my closet and never see anyone else. Who's in charge here?!: Understanding Distributed VCS All hail the SHA My repository, remote repositories Pushing and Pulling Finally we'll look at the vary basic tasks of cloning or initializing a repository and committing to it, then pushing your changes back to a server.

TRANSCRIPT

Page 1: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

GIT WITH THE PROGRAMDrupal Camp LA 2013

Matthew WratherWrather Creative

Page 2: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

ABOUT ME

• Freelance Drupal Developerand Web Generalist since 1997

• Drupal since 4.6

• Most Definitely Available for [email protected](510) WRA-THER

Page 3: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

SOURCES

• A great talk by @merlyn himself, Randal Schwartz CC-BY-SA• On Vimeo at https://vimeo.com/35778382• Slides at http://slidesha.re/z7nQrG

• Pro Git by Scott Chacon CC-BY-NC-SA• Read for free at http://git-scm.com/book

• And many more at http://lmgtfy.com/?q=git+tutorial

Page 4: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

AGENDA

1. Why Use Version Control

2. Git basic concepts

3. Demo

Time for questions after each section.

Page 6: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

QUESTIONS?

Page 7: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

WHAT IS GIT FOR?

Git is for…

• Tracks a tree of related files• Distributed• High Performance• Easy & Fast Branch/Merge• Good Data Integrity• Collaborative

Git is not for…

• Tracking unrelated files• Tracking File Metadata• Binary Files

Page 8: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

WRAP YOUR MIND AROUND

• Distributed: Your repository is complete unto itself.

• Anyone can commit!*

*To their own repo.

• (Once you start fetching and pushing work,permissions come into play.)

• There can still be a central, blessed repo.

• Universal Public Identifiers: SHA1 hashes

Page 9: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013
Page 10: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

OBJECTS IN GIT

• Blobs (actual data)

• Trees (directories of blobs or of other trees)

• A commit, which is:

• A tree

• Zero or more parent commits

• Metadata (commit message, name email, timestamp)

Page 11: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

Page 12: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

WE NEED TO TALKABOUT COMMITMENT

Do this

Work

Stage

Commit

here

Filesystem

Staging Area

Repository

(aka here)

Working Tree

Index

HEAD

by

writing code

git add

git commit

Rinse and Repeat

Page 13: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

Page 14: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

$ git commit

Page 15: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

$ git branch testing

Page 16: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

Page 17: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

$ git checkout testing

Page 18: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

$ subl awesome.module$ git add awesome.module$ git commit -m ‘changed awesome module’

Page 19: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

$ git checkout master

Page 20: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

BRANCHES

Page 21: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

MERGING

Page 22: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

MERGING

$ git checkout -b iss53 # shortcut for:$ # git branch iss53$ # git checkout iss53

Page 23: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

MERGING

Page 24: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

MERGING

Page 25: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

FAST FORWARD MERGE

$ git checkout master$ git merge hotfix

Page 26: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

FAST FORWARD MERGE

Page 27: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

FAST FORWARD MERGE

Page 28: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

FAST FORWARD MERGE

$ git branch -d hotfix

Page 29: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

RECURSIVE MERGE

Page 30: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

RECURSIVE MERGE

$ git checkout master$ git merge iss53

Page 31: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

REBASING

Page 32: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

REBASING

Page 33: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

REBASING

Page 34: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

graphic from Pro Git by Scott ChaconCC-BY-NC-SA

REBASING

$ git checkout experiment$ git rebase master

Page 35: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

Thou shalt not rebase commits that youhave pushed to a remote repository.

Page 36: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

REMOTE REPOSITORIES

• All these things that we’ve done so far happen in the privacy of our own computer and don’t affect anything else.

• You can track what’s going on in other repositories by adding them as “remotes”

git remote add <nickname> <remote-url>

• When you copy a repo using the git clone command,you’ll automatically have a remote called origin

Page 37: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

REMOTE REPOSITORIES

• When you’ve done working, you can “push” your work up to a remote repository

git push <remote-nickname> <branch>

git push origin master

• But if someone else has done work and pushed it to the remote repo, git won’t let you overwrite.

Page 38: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

REMOTE REPOSITORIES

• To find out what’s on the server, you can “fetch” from a remote repository

git fetch <remote-nickname>

git fetch origin

• Remote branches will be tracked locally, prefixed with the remote nickname. The master branch on origin becomes origin/master locally.

Page 39: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

REMOTE REPOSITORIES$ git push origin master

[git error message]

$ git fetch origin$ git merge origin/master$ git push master

[HUGE SUCCESS!]

Page 40: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

QUESTIONS?

Page 41: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

DEMO

Page 42: Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013

THANK YOU!Matthew Wrather • @mwrather

[email protected] • (510) WRA-THER