Pragmatic Guide to Git
-
Upload
confoo -
Category
Technology
-
view
2.375 -
download
53
description
Transcript of Pragmatic Guide to Git
GITPragmatic Guide
Travis Swicegood
Licensed under Creative Commons,Attribution, Share-Alike
#gittalk
some rights reservedpragmatic guide to git by travis swicegood
#gittalk
some rights reservedpragmatic guide to git by travis swicegood
Hi, I’m Travis
some rights reservedpragmatic guide to git by travis swicegood
some rights reservedpragmatic guide to git by travis swicegood
Git is Easy
some rights reservedpragmatic guide to git by travis swicegood
What’s thistalk about?
some rights reservedpragmatic guide to git by travis swicegood
What thistalk isn’t about?
some rights reservedpragmatic guide to git by travis swicegood
Contents
some rights reservedpragmatic guide to git by travis swicegood
Starting Out
some rights reservedpragmatic guide to git by travis swicegood
Daily Work
some rights reservedpragmatic guide to git by travis swicegood
Branches
some rights reservedpragmatic guide to git by travis swicegood
Team Work
some rights reservedpragmatic guide to git by travis swicegood
Glossary
some rights reservedpragmatic guide to git by travis swicegood
Starting Out
some rights reservedpragmatic guide to git by travis swicegood
Installation
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
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
some rights reservedpragmatic guide to git by travis swicegood
Installation–Windows
Cygwin: http://cygwin.org
msysGit:http://code.google.com/p/msysgit/
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–
some rights reservedpragmatic guide to git by travis swicegood
prompt> git --versiongit version 1.7.3.2
Verifying the Install
some rights reservedpragmatic guide to git by travis swicegood
prompt> git --versiongit version 1.7.3.2hub version 1.4.1
My Version
some rights reservedpragmatic guide to git by travis swicegood
GettingHelp
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
some rights reservedpragmatic guide to git by travis swicegood
Configuration
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
some rights reservedpragmatic guide to git by travis swicegood
prompt> git config --global color.ui auto
Colors
some rights reservedpragmatic guide to git by travis swicegood
Creating NewRepositories
some rights reservedpragmatic guide to git by travis swicegood
Repository
some rights reservedpragmatic guide to git by travis swicegood
Commit
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
some rights reservedpragmatic guide to git by travis swicegood
WorkingTree
some rights reservedpragmatic guide to git by travis swicegood
Cloning NewRepositories
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
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
some rights reservedpragmatic guide to git by travis swicegood
Daily Work
some rights reservedpragmatic guide to git by travis swicegood
Seeing What’s Changed
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
some rights reservedpragmatic guide to git by travis swicegood
Staging Changes
some rights reservedpragmatic guide to git by travis swicegood
Index
some rights reservedpragmatic guide to git by travis swicegood
(aka)
StagingArea
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
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
some rights reservedpragmatic guide to git by travis swicegood
Committing Changes
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
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
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
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
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?
some rights reservedpragmatic guide to git by travis swicegood
Staging Changes
(Part II)
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
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
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
some rights reservedpragmatic guide to git by travis swicegood
prompt> git add -p README.rst… editor launches …
Adding Part of a File
some rights reservedpragmatic guide to git by travis swicegood
Undoing Staged
Changes
some rights reservedpragmatic guide to git by travis swicegood
prompt> git reset HEAD README.rstM README.rst
Remove a Staged Change
some rights reservedpragmatic guide to git by travis swicegood
MovingFiles
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
some rights reservedpragmatic guide to git by travis swicegood
DeletingFiles
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
some rights reservedpragmatic guide to git by travis swicegood
SharingChanges
some rights reservedpragmatic guide to git by travis swicegood
SharingChanges
(from 30,000 feet)
some rights reservedpragmatic guide to git by travis swicegood
prompt> git push <remote> [<branch>]… example …prompt> git push origin master
Sending Your Changes
some rights reservedpragmatic guide to git by travis swicegood
prompt> git push <remote> [<branch>]… example …prompt> git push origin master
Sending Your Changes
some rights reservedpragmatic guide to git by travis swicegood
prompt> git pull <remote> [<branch>]… example …prompt> git pull tswicegood master
Grabbing Other’s Changes
some rights reservedpragmatic guide to git by travis swicegood
Told ya…30,000’
some rights reservedpragmatic guide to git by travis swicegood
Branches
some rights reservedpragmatic guide to git by travis swicegood
What’s aBranch?
some rights reservedpragmatic guide to git by travis swicegood
Viewing
some rights reservedpragmatic guide to git by travis swicegood
prompt> git branch* master
Viewing Branches
some rights reservedpragmatic guide to git by travis swicegood
Creating
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
some rights reservedpragmatic guide to git by travis swicegood
Switching
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
some rights reservedpragmatic guide to git by travis swicegood
Create & Switch
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
some rights reservedpragmatic guide to git by travis swicegood
Merging
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
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
some rights reservedpragmatic guide to git by travis swicegood
Fast Forward
master
newest-branch
some rights reservedpragmatic guide to git by travis swicegood
Fast Forward
master
newest-branch
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
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
some rights reservedpragmatic guide to git by travis swicegood
Recursive Merge
master
new-branch
some rights reservedpragmatic guide to git by travis swicegood
Recursive Merge
master
new-branch
some rights reservedpragmatic guide to git by travis swicegood
Rebasing
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
some rights reservedpragmatic guide to git by travis swicegood
Before Rebasing
master
new-branch
some rights reservedpragmatic guide to git by travis swicegood
After Rebasing
master
new-branch
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
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
some rights reservedpragmatic guide to git by travis swicegood
Deleting
some rights reservedpragmatic guide to git by travis swicegood
prompt> git branch -d newest-branchDeleted branch newest-branch (was a053b49).
Deleting Branches
some rights reservedpragmatic guide to git by travis swicegood
Not in Current Branch
master
new-branch
some rights reservedpragmatic guide to git by travis swicegood
prompt> git branch -D new-branchDeleted branch new-branch (was 1a3cdc2).
Really Deleting Branches
some rights reservedpragmatic guide to git by travis swicegood
prompt> git branch -D new-branchDeleted branch new-branch (was 1a3cdc2).
Really Deleting Branches
some rights reservedpragmatic guide to git by travis swicegood
Team Work
some rights reservedpragmatic guide to git by travis swicegood
RemoteRepository
some rights reservedpragmatic guide to git by travis swicegood
Remotes
some rights reservedpragmatic guide to git by travis swicegood
prompt> git remoteprompt>
Viewing Remotes
some rights reservedpragmatic guide to git by travis swicegood
prompt> cd /usr/localprompt> git remotehomebrewrodertswicegood
Viewing Remotes
some rights reservedpragmatic guide to git by travis swicegood
Adding
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
some rights reservedpragmatic guide to git by travis swicegood
Removing
some rights reservedpragmatic guide to git by travis swicegood
prompt> git remote rm <remote>
… example …prompt> git remote rm tswicegood
Removing Remotes
some rights reservedpragmatic guide to git by travis swicegood
Fetching
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
some rights reservedpragmatic guide to git by travis swicegood
RemoteBranches
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
some rights reservedpragmatic guide to git by travis swicegood
You StillHave to Merge
some rights reservedpragmatic guide to git by travis swicegood
Pulling
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
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
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
some rights reservedpragmatic guide to git by travis swicegood
PullingPart 2
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
some rights reservedpragmatic guide to git by travis swicegood
Pushing
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
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
some rights reservedpragmatic guide to git by travis swicegood
TeamWorkflow
some rights reservedpragmatic guide to git by travis swicegood
Fully Distributed
You
Developer JaneDesigner Bob
some rights reservedpragmatic guide to git by travis swicegood
Fully Distributed
You
Developer JaneDesigner Bob
some rights reservedpragmatic guide to git by travis swicegood
Shared Model
You Developer JaneDesigner Bob
some rights reservedpragmatic guide to git by travis swicegood
Lots More
some rights reservedpragmatic guide to git by travis swicegood
Several Books
some rights reservedpragmatic guide to git by travis swicegood
PragProg.com
some rights reservedpragmatic guide to git by travis swicegood
git-scm.com#git (freenode)
some rights reservedpragmatic guide to git by travis swicegood
Travis Swicegoodtravisswicegood.com
@[email protected] http://joind.in/2855