45
INTRODUCTION TO GIT Drupal Camp LA 2015 Matthew Wrather Wrather Creative

Introduction to Git, DrupalCamp LA 2015

Embed Size (px)

Citation preview

INTRODUCTION TO GITDrupal Camp LA 2015

Matthew WratherWrather Creative

RACONTEURBON VIVANT

MAN OF MYSTERY

[email protected]@mwrather

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

AGENDA

1. Why Use Version Control

2. Git basic concepts

3. Demo

Time for questions after each section.

DOESN’T USE VERSION CONTROLslworking on Flickr

CC-BY-NC-SA

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

DEMO

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

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)

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

QUESTIONS?

WE NEED TO TALK ABOUT 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

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

BRANCHES

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

BRANCHES

$ git commit

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

BRANCHES

$ git branch testing

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

BRANCHES

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

BRANCHES

$ git checkout testing

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

BRANCHES

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

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

BRANCHES

$ git checkout master

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

BRANCHES

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

MERGING

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

MERGING

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

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

MERGING

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

MERGING

FAST FORWARD MERGE

$ git checkout master $ git merge hotfix

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

FAST FORWARD MERGE

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

FAST FORWARD MERGE

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

FAST FORWARD MERGE

$ git branch -d hotfix

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

RECURSIVE MERGE

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

RECURSIVE MERGE

$ git checkout master $ git merge iss53

DEMO

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

REBASING

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

REBASING

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

REBASING

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

REBASING

$ git checkout experiment $ git rebase master

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

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.

• As a beginner, you are going to be using other people’s repositories more than you are going to create your own

git clone <remoteUrl>

• <remoteURL> can be HTTP, SSH, or git:// depending on your permissions

REMOTE REPOSITORIES

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

• It’s possible to have many, many remotes. It can be hard to keep track of. You probably don’t need to worry about it.

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.

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.

REMOTE REPOSITORIES$ git push origin master

[git error message]

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

[HUGE SUCCESS!]

DEMO

QUESTIONS?

THANK YOU!Matthew Wrather • @mwrather

[email protected] • (510) WRA-THER