pragmatic guide to git

127
GIT Pragmatic Guide Travis Swicegood Licensed under Creative Commons, Attribution, Share-Alike #gittalk

Upload: confoo

Post on 22-Apr-2015

2.375 views

Category:

Technology


53 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Pragmatic Guide to Git

GITPragmatic Guide

Travis Swicegood

Licensed under Creative Commons,Attribution, Share-Alike

#gittalk

Page 2: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

#gittalk

Page 3: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Hi, I’m Travis

Page 4: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Page 5: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Git is Easy

Page 6: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

What’s thistalk about?

Page 7: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

What thistalk isn’t about?

Page 8: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Contents

Page 9: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Starting Out

Page 10: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Daily Work

Page 11: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Branches

Page 12: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Team Work

Page 13: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Glossary

Page 14: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Starting Out

Page 15: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Installation

Page 16: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

… download latest source from git-scm.com…prompt> make && make install

… if you’re adventurous…prompt> make docs && make install-docs

Installation–Compiling

Page 17: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> apt-get install git-core… optional …prompt> apt-get install git-doc git-svn

Installation–Ubuntu

Page 18: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Installation–Windows

Cygwin: http://cygwin.org

msysGit:http://code.google.com/p/msysgit/

Page 19: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> brew install git

Installation–OS X

Git OS X Installer:http://code.google.com/p/git-osx-installer/

–OR–

Page 20: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git --versiongit version 1.7.3.2

Verifying the Install

Page 21: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git --versiongit version 1.7.3.2hub version 1.4.1

My Version

Page 22: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

GettingHelp

Page 23: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git help

prompt> git help <some command>

prompt> open http://j.mp/gitdocs/

Built-in Help

Page 24: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Configuration

Page 25: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git config --global user.name \ “Travis Swicegood”

prompt> git config --global user.email \ “[email protected]

User & Email

Page 26: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git config --global color.ui auto

Colors

Page 27: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Creating NewRepositories

Page 28: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Repository

Page 29: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Commit

Page 30: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git init

… example …prompt> mkdir /work/some-repoprompt> cd /work/some-repoprompt> git init

Initialization

Page 31: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

WorkingTree

Page 32: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Cloning NewRepositories

Page 33: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git clone <some repo>

… example …prompt> git clone \ git://github.com/tswicegood/bobby-tables.gitprompt> cd bobby-tables

Cloning

Page 34: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git clone <some repo>

… example …prompt> git clone \ git://github.com/tswicegood/bobby-tables.gitprompt> cd bobby-tables

Cloning

Page 35: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Daily Work

Page 36: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Seeing What’s Changed

Page 37: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git status

… example …prompt> git status# On branch masternothing to commit (working directory clean)

Status

Page 38: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Staging Changes

Page 39: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Index

Page 40: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

(aka)

StagingArea

Page 41: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git status# On branch master# Untracked files:# (use "git add <file>..." to include in what… ## README.rst

Adding a New File

Page 42: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git add README.rstprompt> git status# On branch master# Changes to be committed:# (use "git rm --cached <file>..." to unstage)## new file: README.rst

Adding a New File

Page 43: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Committing Changes

Page 44: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git commit -m “some great message”[master 600f084] some great message 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.rst

Creating a Commit

Page 45: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git commit -m “some great message”[master 600f084] some great message 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.rst

Creating a Commit

Page 46: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git commit -m “some great message”[master 600f084] some great message 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.rst

Creating a Commit

Page 47: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git commit -m “some great message”[master 600f084] some great message 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.rst

… or use the editor …prompt> git commit

Creating a Commit

Page 48: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

GIT_EDITOR <-- environment varcore.editor <-- set with git config --globalVISUAL <-- environment varEDITOR <-- environment varvi <-- when all else fails

Git’s Editor?

Page 49: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Staging Changes

(Part II)

Page 50: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git add README.rstprompt> git status# On branch master# Changes to be committed:# (use "git rm --cached <file>..." to unstage)## modified file: README.rst

Adding an Existing File

Page 51: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git commit -m “great message” \ README.rst[master 3dc20b0] great message 1 files changed, 1 insertions(+), 0 deletions(-)

Commit Existing File

Page 52: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git commit -m “great message” -a[master be1b8dc] great message 1 files changed, 1 insertions(+), 0 deletions(-)

Commit All Changes

Page 53: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git add -p README.rst… editor launches …

Adding Part of a File

Page 54: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Undoing Staged

Changes

Page 55: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git reset HEAD README.rstM README.rst

Remove a Staged Change

Page 56: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

MovingFiles

Page 57: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git mv README.rst README.txtprompt> git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## renamed: README.rst -> README.txt

Moving a File

Page 58: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

DeletingFiles

Page 59: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git rm README.txtrm 'README.txt'prompt> git status# On branch master…# deleted: README.txt

Deleting a File

Page 60: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

SharingChanges

Page 61: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

SharingChanges

(from 30,000 feet)

Page 62: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git push <remote> [<branch>]… example …prompt> git push origin master

Sending Your Changes

Page 63: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git push <remote> [<branch>]… example …prompt> git push origin master

Sending Your Changes

Page 64: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git pull <remote> [<branch>]… example …prompt> git pull tswicegood master

Grabbing Other’s Changes

Page 65: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Told ya…30,000’

Page 66: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Branches

Page 67: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

What’s aBranch?

Page 68: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Viewing

Page 69: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git branch* master

Viewing Branches

Page 70: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Creating

Page 71: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git branch <new branch> [<existing>]

… example …prompt> git branch new-branchprompt> git branch* master new-branch

Creating a New Branch

Page 72: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Switching

Page 73: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout new-branchSwitched to branch 'new-branch'prompt> git branch master* new-branch

Switching Branches

Page 74: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Create & Switch

Page 75: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout -b newest-branchSwitched to branch 'newest-branch'prompt> git branch master new-branch* newest-branch

Switching Branches

Page 76: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Merging

Page 77: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout masterSwitched to branch 'master'prompt> git merge newest-branchUpdating 94f1967..a053b49Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 foo

Merging Branches

Page 78: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout masterSwitched to branch 'master'prompt> git merge newest-branchUpdating 94f1967..a053b49Fast-forward 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 foo

Merging Branches

Page 79: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Fast Forward

master

newest-branch

Page 80: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Fast Forward

master

newest-branch

Page 81: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git merge new-branchMerge made by recursive. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bar

Merging Branches

Page 82: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git merge new-branchMerge made by recursive. 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bar

Merging Branches

Page 83: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Recursive Merge

master

new-branch

Page 84: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Recursive Merge

master

new-branch

Page 85: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Rebasing

Page 86: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout new-branchSwitched to branch 'new-branch'prompt> git rebase masterFirst, rewinding head to replay your work on top of it...Applying: …

Rebasing Branches

Page 87: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Before Rebasing

master

new-branch

Page 88: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

After Rebasing

master

new-branch

Page 89: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout new-branchSwitched to branch 'new-branch'prompt> git rebase masterFirst, rewinding head to replay your work on top of it...Applying: …

Rebasing Branches

Page 90: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git checkout new-branchSwitched to branch 'new-branch'prompt> git rebase 1a3cdc2First, rewinding head to replay your work on top of it...Applying: …

Rebasing Branches

Page 91: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Deleting

Page 92: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git branch -d newest-branchDeleted branch newest-branch (was a053b49).

Deleting Branches

Page 93: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Not in Current Branch

master

new-branch

Page 94: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git branch -D new-branchDeleted branch new-branch (was 1a3cdc2).

Really Deleting Branches

Page 95: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git branch -D new-branchDeleted branch new-branch (was 1a3cdc2).

Really Deleting Branches

Page 96: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Team Work

Page 97: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

RemoteRepository

Page 98: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Remotes

Page 99: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git remoteprompt>

Viewing Remotes

Page 100: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> cd /usr/localprompt> git remotehomebrewrodertswicegood

Viewing Remotes

Page 101: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Adding

Page 102: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git remote add <remote> <url>

… example …prompt> git remote add tswicegood \ git://github.com/tswicegood/homebrew.gitprompt> git remotetswicegood

Adding Remotes

Page 103: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Removing

Page 104: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git remote rm <remote>

… example …prompt> git remote rm tswicegood

Removing Remotes

Page 105: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Fetching

Page 106: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git fetch <remote>

… example …prompt> git fetch tswicegoodremote: Counting objects: 3, done.… clipped … * [new branch] master -> tswicegood/master

Fetching Changes

Page 107: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

RemoteBranches

Page 108: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git branch -r tswicegood/master

… or everything at once …prompt> git branch -a * master remotes/tswicegood/master

Remote Branches

Page 109: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

You StillHave to Merge

Page 110: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Pulling

Page 111: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git pull <remote> <branch>

… example …prompt> git pull tswicegood master… clipped … * branch master -> FETCH_HEADFast-forward… clipped …

Pulling Changes

Page 112: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git pull <remote> <branch>

… example …prompt> git pull tswicegood master… clipped … * branch master -> FETCH_HEADFast-forward… clipped …

Grokking Refspecs

Page 113: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git pull <remote> \ <remote branch>:<local branch>

… examples …prompt> git pull tswicegood masterprompt> git pull tswicegood master:masterprompt> git pull tswicegood dev:my-dev

Grokking Pull Refspecs

Page 114: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

PullingPart 2

Page 115: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git pull --rebase <remote> <branch>

… example …prompt> git pull --rebase tswicegood master… clipped … * branch master -> FETCH_HEADFirst, rewinding head to replay your work on top of it... clipped …

Pulling Changes

Page 116: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Pushing

Page 117: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git push <remote> <branch>

… example …prompt> git push tswicegood master… clipped … * [new branch] new-branch -> new-branch

Pushing Changes

Page 118: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

prompt> git push <remote> \ <local branch>:<remote branch>

… examples …prompt> git push tswicegood masterprompt> git push tswicegood master:masterprompt> git push tswicegood my-dev:dev

Grokking Push Refspecs

Page 119: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

TeamWorkflow

Page 120: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Fully Distributed

You

Developer JaneDesigner Bob

Page 121: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Fully Distributed

You

Developer JaneDesigner Bob

Page 122: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Shared Model

You Developer JaneDesigner Bob

Page 123: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Lots More

Page 124: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Several Books

Page 125: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

PragProg.com

Page 126: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

git-scm.com#git (freenode)

Page 127: Pragmatic Guide to Git

some rights reservedpragmatic guide to git by travis swicegood

Travis Swicegoodtravisswicegood.com

@[email protected] http://joind.in/2855