Git FoundationsAn exploration of the Git toolbox
Officialtrainingcurriculumv3.1.0©2012,GitHub,Inc.
Hello!
Matthew McCullough
@matthewmccull
Ma hew who?
‣Open source contributor
‣Build tool book co-author
‣Continuous integration book co-author
‣5 year Git evangel...
Welcome
‣Questions, Pacing
‣Ask questions at any time. Don't wait!
‣Suggest course pacing slowing/speeding up
Git
Where’s this coming from?
Git
Git?
Open Source
Git?
bash scripts C code
Git?
≉
Git
-noun
British Slang. an unpleasant
or contemptible person
-Oxford English Dictionary
“
”
I'm an egotistical bastard, and I name
all my projects after myself.
First Linux, now git.
-Linus Torvalds
“
”
Git
What is this thing?
GIT - the stupid content tracker
"git" can mean anything, depending on your mood.
* random three-letter combination that i...
file trackercontent
Git?
centralized version control systems have matured
CVS
Subversion
PVCS
Perforce
Clear
CaseSource
Safe
RCS
Folders
Git?
small improvements, but no
radical innovation
Git?
Linus?
Git?
I did end up using CVS for 7 years at a commercial
company and I hate it with a passion...
The slogan of Subversion for a ...
VCS reboot
Git?
50% Distributed Version Control
Git?
50% Git Concepts
with
1997
code co-op
2001
arch
2003
monotone
2003
SVK
2003
darcs
2005
bazaar
2005
mercurial
2005
git
time to mature
most unique improvements
largest DVCS user base
Setup
Testing Git
Setting up Git
Check your Git version...
git --version
Setup
What is a Git install?
Setting up Git
binaries on your $PATH
Using
Creating a repository
Creating A Repository
# Green field project
$ git init newproject
$ cd newproject
# ...start coding
Creating A Repository
‣Create our first repository
Creating A Repository
or if you already have source code
Creating A Repository
# Legacy project tree
$ cd existingproject
$ git init
# Add all the code
$ git add .
$ git commit -m...
Using
What’s in .git?
Contents of .git
.git
!"" COMMIT_EDITMSG
!"" HEAD
!"" MERGE_RR
!"" config
!"" description
!"" hooks
#   !"" pre-commit.sam...
Three stage thinking
‣Explore the .git folder
Configuration
Display
Configuring Git
Query existing configuration
Configuring Git
All entries
Configuring Git
#List all config values
git config --list
Configuring Git
Single entry
Configuring Git
#Query effective value of a single key
git config section.key
git config section.subsection.key
Configuring Git
#Show a specific config value
git config user.name
git config user.email
Configuration
Layers
Config Targets
git config --system
#Saves to /etc/gitconfig
Config Targets
git config --global
#Saves to ~/.gitconfig
Config Targets
git config --local
#Saves to .git/config
Configuring Git
#Configure a setting in a .git repository
git config __________
git config --local __________
#Configure a ...
Config Targets
Git configuration reading & writing
targets local by default
Configuration
Inheritance
Config Inheritance
Query existing configuration by layer
Config Inheritance
#Query a single key in a single layer
git config --<WHERE> section.key
git config --<WHERE> section.subs...
Config Inheritance
#List all system config values
git config --system --list
Config Inheritance
#List all global config values
git config --global --list
Config Inheritance
#List all local config values
git config --local --list
Config Inheritance
#List effective config values
git config --list
Configuration
Set user identity
Set User Identity
any config at any layer
Set User Identity
#List the current config
git config --global user.name "Fird Birfle"
git config --global user.email "fir...
Set User Identity
just a string
Set User Identity
user identity
Set User Identity
user identityauthenticationnot
Set User Identity
user identityauthenticationauthorizationnot
Configuration
Display color
Set Console Color
console color
Set Console Color
git config --global color.ui always
Set Console Color
git log 
--graph 
--decorate 
--simplify-by-decoration 
--abbrev-commit 
--date=relative 
--pretty=oneli...
Configuring Git
git log 
--graph 
--decorate 
--simplify-by-decoration 
--abbrev-commit 
--date=relative 
--pretty=oneline ...
Set Console Color
Bleh!
Set Console Color
output destination detection
Set Console Color
git config --global color.ui auto
# or the identical effect with...
git config --global color.ui true
Set Console Color
git log 
--graph 
--decorate 
--simplify-by-decoration 
--abbrev-commit 
--date=relative 
--pretty=oneli...
Set Console Color
when you need itColor
Set Console Color
only when you need itColor
Configuration
Line endings
Line Endings
line endings
Line Endings
VS
Line Endings
VS
LF
CRLF
Line Endings
default is to do nothing
Line Endings
http://help.github.com/dealing-with-lineendings/
Line Endings
#Force files to be LF in the repo,
# even on Mac/Linux
git config --global core.autocrlf input
#Force Windows...
Line Endings
#Force files to be LF during `add`
git config --global core.autocrlf input
#Force Windows to convert to CRLF
...
warn about conversion
Line Endings
#Never complain about line ending conversion
git config --global core.safecrlf false
#Warn, but allow line en...
Configuration
Secure Sockets Host (SSH)
Configuring SSH
‣Generate an ssh key pair
Configuring SSH
ssh key pair
Configuring SSH
$ ssh-keygen -t rsa -C”For GitHub”
Configuring SSH
$ ssh-keygen -t rsa -C”For GitHub”
Configuring SSH
Configuring SSH
# Verify the files were created
$ cd ~/.ssh
$ ls
Configuring SSH
Configuring SSH
‣id_rsa is the private half of the key
‣Keep this uncompromisingly secret
‣id_rsa.pub is the public half of...
Configuring SSH
#GitHub sanity test
ssh -T git@github.com
> Hi matthewmccullough! You've successfully
authenticated, but Gi...
Configuring SSH
#GitHub sanity test with verbose SSH
ssh -v git@github.com
>OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1...
Using Git
Three Stage Thinking
Three stage thinking
‣Edit
‣Add
‣Commit
Three stage thinking
Working Staging Repo
add
commit
edit
Three stage thinking
‣shopping cart
‣put things in
‣take things out
‣purchase at register
Three stage thinking
Three stage thinking
‣database transaction
‣update values
‣insert rows
‣delete rows
‣commit transaction
Three stage thinking
only onestaging area
Three stage thinking
Working Staging Repo
add
commit
edit
Setup
Commit Message Editor
Commit Message Editor
✓? Used the VI editor?
Commit Message Editor
I
y
;WQ
Commit Message Editor
an alternate editor?
Commit Message Editor
$EDITOR environment variable
O
ption
1
Commit Message Editor
$ export EDITOR=<AnEditorOnYourPath>
O
ption
1
Commit Message Editor
GitPad wraps Notepad (or $EDITOR)
O
ption
2
Commit Message Editor
http://github.com/github/GitPad
O
ption
2
Commit Message Editor
Run GitPad
...registers & wraps Notepad as the editor
O
ption
2
Commit Message Editor
Git-specific configuration option
O
ption
3
Commit Message Editor
#for TextMate on Mac
git config --global core.editor "mate -w"
#for Notepad2 on Windows
git config -...
Commit Message Editor
O
ption
3
Commit Message Editor
‣Toggle to alternate editor
‣Make a commit
‣Test that the new editor pops up
Usage Basics
Adding & committing code
Three stage thinking
$ vi first.html
$ git status
$ git add first.html
$ git commit -m”First commit”
Three stage thinking
‣Write a sample HTML or TXT file
‣Inspect Git’s status
‣Add code (stage it)
‣Commit code
Usage Basics
Diff-ing changes
Three stage thinking
What has changed that we
haven’t committed?
Three stage thinking
# Show the unstaged changes
$ git diff
Three stage thinking
Working Staging Repo
$ git diff
Three stage thinking
# Show the staged changes
$ git diff --staged
Three stage thinking
Working Staging Repo
$ git diff --staged
Three stage thinking
# Show uncommitted changes
$ git diff HEAD
Three stage thinking
Working Staging Repo
$ git diff HEAD
Usage Basics
Limiting diff output
Limiting Diff Output
Word changes instead of entire lines?
Limiting Diff Output
git diff --color-words
Limiting Diff Output
$ git diff
diff --git a/first.txt b/first.txt
index cbb1543..e99dea9 100644
--- a/first.txt
+++ b/fir...
Limiting Diff Output
git diff --word-diff
Limiting Diff Output
$ git diff
diff --git a/first.txt b/first.txt
index cbb1543..e99dea9 100644
--- a/first.txt
+++ b/fir...
Usage Basics
Whitespace diff
Limiting Diff Output
whitespace suppressed?
Limiting Diff Output
refactoring review
Limiting Diff Output
git diff -w
Limiting Diff Output
$ git diff
diff --git a/first.txt b/first.txt
index 09195c0..f2c3243 100644
--- a/first.txt
+++ b/fir...
Usage Basics
Limiting diff by type
Limiting Diff Output
# Added (A)
# Copied (C)
# Deleted (D)
# Modified (M)
# Renamed (R)
# Type changed (T)
# Unmerged (U)...
Limiting Diff Output
# Added (A)
# Copied (C)
# Deleted (D)
# Modified (M)
# Renamed (R)
# Type changed (T)
# Unmerged (U)...
Limiting Diff Output
# Added (A)
# Copied (C)
# Deleted (D)
# Modified (M)
# Renamed (R)
# Type changed (T)
# Unmerged (U)...
Limiting Diff Output
$ git status -s -u
D README
MM first.txt
$ git diff --diff-filter=M
diff --git a/first.txt b/first.tx...
Usage Basics
Reviewing history
Three stage thinking
view history of commits
Three stage thinking
# Show all history
git log
Three stage thinking
# Show all history with filenames
git log --stat
Three stage thinking
# Show all history with patches
git log --patch
git log -p
Three stage thinking
# Limit the output entries
git log -1
git log -3
git log -5
Three stage thinking
# Control the output format
git log --pretty=full
Three stage thinking
# Control the output format
git log --pretty=fuller
Three stage thinking
# Control the output format
git log --pretty=email
Three stage thinking
# Control the output format
git log --pretty=raw
Three stage thinking
# Control the output format
git log --pretty=format:<pattern>
Three stage thinking
# Limit the output to added files
git log --diff-filter=A
Usage Basics+
Ignoring files
Ignoring Files
Untracked Tracked
Unmodified
Tracked
Modified
Tracked
Staged
Ignored
commit
add
edit
add
rm
ignore
Ignoring Files
suppressing files from being
reported as untracked
Ignoring Files
glob patterns
Ignoring Files
$ vim .gitignore
#Add glob patterns, one per line
*.log
*.tmp
Ignoring Files
in-memory recursive evaluation
Ignoring Files
$ vim .gitignore
#Add glob patterns, one per line
*.log
*.tmp
target
output/
!special.log
Ignoring Files
‣Ignore files via local .gitignore
Usage Basics+
Open source .gitignores
Open Source Ignores
Preconfigured .gitignore files
Open Source Ignores
http://github.com/github/gitignore
copy and paste(the one time it’s OK to do it)
Usage Basics+
Global ignores
Global Ignore
Global .gitignore ?
Global Ignore
off by default
Global Ignore
$ git config --global
core.excludesfile "~/.gitignore"
Global Ignore
$ vim ~/.gitignore
# Operating system and editor temp files
# Generally redundant over project .gitignores
t...
Global Ignore
‣Ignore files via global ~/.gitignore
Usage Basics+
Removing files
The Git File Workflow
Untracked Tracked
Unmodified
Tracked
Modified
Tracked
Staged
Ignored
commit
add
edit
add
rm
ignore
The Git File Workflow
Removing Files
The Git File Workflow
# Directly remove & stage
$ git rm <FILENAME>
The Git File Workflow
# Remove with OS or tool,
# not integrated with Git
$ rm <FILENAME>
# Staging area says it is
# delet...
The Git File Workflow
# Remove with OS or tool
# then follow up with git add
$ rm <FILENAMES>
$ git add -u .
The Git File Workflow
‣ Remove files
Usage Basics+
Moving files
The Git File Workflow
Untracked Tracked
Unmodified
Tracked
Modified
Tracked
Staged
Ignored
commit
add
edit
add
rm
ignore
The Git File Workflow
Moving Files
The Git File Workflow
# Directly move & stage
$ git mv <FILENAME> <NEWFILENAME>
The Git File Workflow
# Move with OS or tool,
mv <FILENAME> <NEWFILENAME>
# Then follow up with git add
git add -A .
The Git File Workflow
‣ Rename (move) files
‣ View history of the move
Usage Basics+
Similarity index
Similarity Index
no "move" primitive
Similarity Index
“similarity index”
Similarity Index
score of sameness
Usage Basics+
Similarity index for moves
Similarity Index
# Move with OS or tool,
$ mv <FILENAME> <NEWFILENAME>
# Follow up by staging everything
$ git add -A .
# ...
why no renames in history?
Similarity Index
# Renames shown
git log --stat -M
Similarity Index
‣ Rename (move) files with changes
‣ Essentially, a refactoring workflow
Usage Basics+
Similarity index for copies
Similarity Index
# Copies & renames shown
# (superset of -M)
git log --stat -C
Similarity Index
‣Copy a file to a new filename
‣Add and commit it
‣Log it using our -C option
“For performance reasons, by
default, -C option finds
copies only if the original file
of the copy was modified in
the sam...
Similarity Index
‣Modify a file and copy it (in the same commit)
‣Log using the -C option
“The --find-copies-harder flag makes the
command inspect unmodified files as
candidates for the source of copy. This
is a ...
Similarity Index
# Copies & renames shown
# (superset of -M)
git log --stat -C -C
git log --stat --find-copies-harder
Similarity Index
‣Log the same file using our -C -C option
Usage Basics+
Similarity index for blame
Similarity Index
# File authoring shown
git blame rerere.c
Similarity Index
# True source of code shown
git blame rerere.c -C
Similarity Index
5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 1) #include "cache.h"
c455c87c (Johannes Schindelin 200...
Similarity Index
5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 1) #include "cache.h"
c455c87c rerere.c (Johan...
Network
Offline design
Offline
‣Local repository is a full copy of the remote
‣Clone fetches all branches and tags
‣Almost all activities happen o...
More available connectivity
More demand to work without
connectivity?
Offline
nice benefit,
but wrong reason
Offline
batched network access
Offline
Offline
Checkout a branch
Add changes
Commit changes
Branch changes
Log history
Grep history
Stash pending changes
Tag a co...
Offline
give up incremental revision numbers
Offline
‣ Using every command offline
Network
Cloning protocols
Cloning Repositories
‣Git supports many cloning protocols
‣file
‣git
‣ssh
‣http
Cloning Repositories
‣file
‣git clone file://myrepos/project
‣git clone /myrepos/project
Cloning Repositories
‣git
‣git clone git://server/project.git
Cloning Repositories
‣ssh
‣ git clone git+ssh://user@server:project.git
‣ git clone user@server:project.git
Cloning Repositories
‣http (dumb)
‣git clone http://server/project.git
‣git clone https://server/project.git
Cloning Repositories
‣http (smart)
‣git clone http://server/project.git
‣git clone https://server/project.git
Cloning Repositories
‣ Clone hellogitworld
‣ git clone
Network
Proxy servers
Cloning Repositories
‣Git Configuration
‣git config --global http.proxy “<URL>”
Network
Speed
‣git: git
‣hg: mercurial
‣bzr: bazaar
data from http://whygitisbetterthanx.com/#git-is-fast
git svn
Init
git svn
Status
git svn
Diff
git svn
Tag
git svn
Log
git...
Speed
‣ Add, commit and push 1000 files
Network
Namespaces
Namespaces
Local Remote Upstream
Namespaces
#List local branches
git branch
Namespaces
Local Remote Upstream
Namespaces
#List remote branches
git branch -r
Namespaces
Local Remote Upstream
Namespaces
#List all branches
git branch -a
Namespaces
Local Remote Upstream
Namespaces
#List upstream branches
git ls-remote origin
Namespaces
Local Remote Upstream
Network
Namespace operations
Namespaces
Local Remote Upstream
commit
fetch
push
clone clone clone
push
pull pull pull
Network
The commit lifecycle
Namespaces
Commit
Push
Pull
Namespaces
‣git commit
‣Transactionally save code snapshot
‣Commit to local branch
‣Operate on local disk
Namespaces
Commit
Push
Pull
Namespaces
‣git push <remote>
‣Send code to an upstream server
‣Update remote branches
Namespaces
Commit
Push
Pull
Namespaces
‣git pull <remote>
‣Retrieve upstream objects
‣Update remote branch
‣Merge changes into local branch
‣Commit th...
Namespaces
Local Remote Upstream
commit
fetch
push
clone clone clone
push
pull pull pull
Network
Remotes
Remotes
Remotes are just symbolic names
Remotes
You can have as many as you like
Remotes
The default name is origin if you’ve cloned
Remotes
Remote-tracking branches are locally immutable
(conceptually)
Remotes
Local Remote Upstream
Remotes
‣ Adding remotes
‣ Fetching from remotes (upstream)
Network
Pruning deletions
‣ Purge remote branches that have been removed from an
upstream repository
‣git remote prune <REMOTENAME>
Remotes
‣Deleting upstream branches
‣Pruning locally
Architecture
Plumbing and Porcelain
Plumbing and Porcelain
Command Composition
Plumbing is the set of low level utilities
Command Composition
Porcelain is the set of end user commands
Command Composition
Porcelain is comprised of plumbing
Command Composition
Command Composition
git-add git-am git-archive git-bisect git-branch git-bundle git-
checkout git-cherry-pick git-citool git-clean git-clone g...
pull is comprised of fetch + merge
Command Composition
checkout -b is comprised of branch + checkout
Command Composition
log HEAD is comprised of rev-parse + log
Command Composition
Aliases
Command shortcuts
Aliases
‣Shortcuts for common commands
‣Create your own recipe
‣Largely the same as shell aliases
Aliases
# Alias for status as 's'
git config --global alias.s "status -u -s"
Aliases
‣ Add an alias
Aliases
# Alias for log with file name as 'l'
git config --global alias.l "log --stat -C"
Aliases
# Alias showing all branches to 'br'
git config --global alias.br "branch -a"
Aliases
# Alias for commit-no-staging to 'cns'
git config --global alias.cns "commit -a"
Aliases
# Alias for shell pull then push to 'sync'
$ git config --global alias.sync
"!git pull && git push"
Aliases
# Alias for crummy-commit-file-quick
$ git config --global alias.ccfq
"!sh -c 'git add $1 && git commit -m"Placeho...
Aliases
‣ Matthew's Aliases
‣ https://github.com/matthewmccullough/git-workshop/blob/master/
workbook/examples/config/.gitc...
Architecture
Storage
Typical SCMs use delta storage
Storage
CVS / Subversion / darcs / Mercurial
Storage
Storage
v1 v2 v3 v4
File A
File B
File C
File A
File B File B
File C
v5
File A
File BFile B
Δ Δ
Δ
Δ ΔΔΔ
Checkin
Checkin Checkin
Checkin
Checkin
Checkin
Checkin
Checkin
Checkin
Checkin
Checkin
Delta storage gets slower as the h...
Git uses DAG storage
Storage
Directed Acyclic Graph
Storage
Storage
Copy of the entire tree per checkin
Storage
cp -r srcfolder srcfolder.prev
Storage
Why?
Storage
Storage
v1 v2 v3 v4
File A
File B
File C
File A
File B File B
File C
v5
File A
File BFile B
File A File A
File C File C Fi...
hard link to existing identical blobs
Storage
Storage
v1 v2 v3 v4
File A
File B
File C
File A
File B File B
File C
v5
File A
File BFile B
File A File A
File C File C Fi...
zlib deflates each blob at commit
Storage
Storage
v1 v2 v3 v4
File A
File B
File C
File A
File B File B
File C
v5
File A
File BFile B
File A File A
File C File C Fi...
zlib deflates the entire repo
Storage
Storage
v1 v2 v3 v4
File A
File B
File C
File A
File B File B
File C
v5
File A
File BFile B
File A File A
File C File C Fi...
Storage
2100 MBbecame
205 MB
Act I
Architecture
Hashes
Hashes
centralized VCSs use sequential revision numbers
Hashes
Git uses a SHA-1 hash
Hashes
40 hex characters
(20 bytes)
Hashes
9AB223D28B1AA46EF1780B22F304982E39872C34
Hashes
Hashes
9AB223D28B1AA46EF1780B22F304982E39872C34
<html>
<body>
<p>This is a test</p>
<img src="http://ai.com/icon.gif">
</b...
use as little of it as is unique
Hashes
Architecture
Hash shortcuts
commitish & treeish
Hashes
commitish
Hashes
= shorthand for commit hashes
treeish
Hashes
= shorthand for tree hashes
9AB22F
a certain commit
Hashes
9AB22F^
one commit before a certain commit
Hashes
9AB22F^^
two commits before a certain commit
Hashes
9AB22F~5
five commits before a certain commit
Hashes
9AB223..56CD77
between these two commits
Hashes
HEAD
the most recent commit on this branch
Hashes
HEAD^
one commit before the most recent commit
Hashes
HEAD~2
two commits before the most recent commit
Hashes
HEAD..HEAD^^^
between the given recent commits
Hashes
master
the most recent commit on this branch
Hashes
master^^
two commits before the most recent commit on this branch
Hashes
master~5
five commits before the most recent commit on this branch
Hashes
remotes/origin/master
the most recent commit on this remote tracking branch
Hashes
origin/master
the most recent commit on this remote tracking branch
Hashes
Hashes
Navigate with commitish on
commit, status, & log
Architecture
Hash relationships
Hashes
‣Blob
‣Tree
‣Commit
‣Tag
Hashes
tree
tree: 7e8b1 web
blob: 9ab16 index.html
a10b3
tree
blob: 8d162 logo.jpg
blob: 51d22 draw.js
7e8b1commit
tree: a...
Hashes
v1 v2 v3
commit
tree: 9a87b
parent: nil
author: Fird
committer: Matthew
message:
Major refactoring
of the Javascrip...
Hashes
RELEASE_1.0 HEAD
bug979branch
commit
c67db
commit
9bd21
commit
1c2d7
commit
8c2d1
commit
1bdcd
commit
2daa1
Branching
Creating branches
Branches
default branch name is master
Branches
master doesn’t have any special privileges
Branches
Local Remote Upstream
Branches
# Creating a branch
git branch <BRANCHNAME>
RELEASE_1.0 HEAD
bug979branch
commit
c67db
commit
9bd21
commit
1c2d7
commit
8c2d1
commit
1bdcd
commit
2daa1
Hashes
‣Create a new local branch from HEAD
Branches
# Creating a branch
git branch <BRANCHNAME> HEAD
Branches
# Creating a branch
git branch <BRANCHNAME> <REF>
RELEASE_1.0 HEAD
bug979branch
commit
c67db
commit
9bd21
commit
1c2d7
commit
8c2d1
commit
1bdcd
commit
2daa1
Hashes
‣Create a new local branch from a branch
Branching
Branch as experiments
Branches
What do cheap branches enable?
Branches
‣Experimentation
‣
Branches
‣Experimentation
‣Safe experimentation
Branches
Better reuse of units of work
Hashes
‣Create a branch for an experiment
‣Delete the failed experiment
Branching
Branch frequency
Branches
When should you branch?
Branches
The answer is always
Branches
Branches isolate volatile work
Branches
Branches cost a mere 20 bytes
Branches
We’ve always wanted to branch often
It’s just been too expensive, polluting, or ceremonious
Hashes
‣Show branches on the Git project
Branching
Branch lifetimes
Branches
‣Branched by lifetime
‣ Product
‣ Integration
‣ Feature
‣ Story
‣ Idea
Branches
product
integration
feature
story
idea
product
v1.0 integration
story1 story2
v1.5 integration
story3
Branches
Branches
Local Remote Upstream
Integ
Product
Integ
Product
Integ
Product
Branches
Local Remote Upstream
Idea
Story
Feature FeatureFeature
Integ
Product
Integ
Product
Integ
Product
Branches
Local Remote Upstream
Idea
Story
Feature FeatureFeature
Integ
Product
Integ
Product
Integ
Product
Branches
‣Branch from the master branch
‣Merge from the topic branch
‣Destroy the topic branch
Branching
Stashes
Stash
super quick branch
Stash
local-only branch
Stash
‣Numbered branch
‣Stack based implementation
‣Push, Peek, and Pop operations
(But has direct entry access too)
Stash
creating a stash
Stash
# Stash your pending changes
git stash
Stash
inspecting the stash
Stash
# List your stashes
git stash list
Stash
noting the stash
Stash
# Stash your pending changes
git stash save “<Message>”
Stash
# List your stashes
git stash list
Stash
using the stash
Stash
# Merge & delete the latest stash
git stash pop
Stash
# Merge & delete a stash
git stash pop stash@{0}
Stash
# Merge & keep the latest stash
git stash apply
Branches
‣Stash modified changes
‣Stash staged changes
‣Apply stashed changes
Stash
converting a stash
Stash
# Convert a stash to a branch
git stash branch <newbr>
Stash
# Convert a stash to a branch
git stash branch <newbr> stash@{3}
Branches
‣Convert a stash to a branch
Tagging
Tag uses
tags as a first class data type
taggingas a cheap operation
New ways to use tags?
Tagging
‣Tagging at each level of approval
‣Dev
‣CM
‣QA
‣Production
Tagging
Tag types
Tagging
reference,
annotated and
signed tag types
Tagging
Reference tag
Tagging
reference tag...
Tagging
# Tag HEAD
git tag <TAGNAME>
Tagging
# Tag an existing ref
git tag <TAGNAME> <REF>
Tagging
# List known tags
git tag
Tagging
# Show a tag’s contents
git show tag
Tagging
‣Tag a revision
‣Start a branch from a tag
Tagging
Annotated tag
Tagging
annotated tag...
Tagging
git tag -a <TAGNAME>
Tagging
git show <TAGNAME>
Tagging
‣Tag a revision with an annotated tag
Tagging
Signed tag
Tagging
signed tag...
Tagging
git tag -s <TAGNAME>
Tagging
git show <TAGNAME>
Tagging
‣Tag a revision with a signed tag
Tagging
Transmitting tags
Tagging
Tags don't push by default
Tagging
# Push all tags
git push <remote> <tag>
Tagging
# Push all tags
git push --tags
‣Push a specific tag
‣Push all tags
Tagging
Tags do fetch by default
‣Fetch all tags
Tagging
but the refspec doesn’t say to
‣Inspect .git/config refspec
Merging
The basics
Merging
very traditional merge of a branch
Merging
git checkout master
git merge <featurebranch>
a32
2e2
e69
d19
8b3
Branch
Master/Trunk/MainLatest
Merging
Recursive
Merge
9f1 Mergee698b3
strategy: recursive
result: no conflicts
a32
e69
d19
Branch
Master/Trunk/MainLatest
Merging
Fast Forward
Merge
Merge
a32
e69
d19
Master/Trunk/MainLatest
Merging
FF
Merge
strategy: recursive
result: fast forward
a32
2e2
e69
d19
8b3
Branch
Master/Trunk/MainLatest
Merging
Conflicting
Merge
Merge
9f1
e698b3
Fix Conflict
strategy: recursive
result: conflicting
Merging
Octopus
Merging
git checkout master
git merge <fb1> <fb2> <fb3>
strategy: octopus
Merging
Subtree
Merging
git checkout master
git merge -s subtree <fb1>
Merging
git checkout master
git merge --squash -s subtree <fb1>
strategy: subtree
Tagging
‣Merge a local branch
‣Merge a remote branch
Rebasing
What is rebasing?
rebasing is not a merge
Rebasing
rebasing is a preparation for a merge
Rebasing
Merges weave multiple old changes into
a new unifying commit
Rebasing
Rebase reorders the chosen commits
before your branch work
Rebasing
simulates team members taking turns working
(one person at a time)
Rebasing
Rebasing
Rebasing on a branch
Rebasing
git pull --rebase
Retrieve upstream changes and
relocate your local changes to the end
Rebasing
Rebasing
git pull --rebase
# is the same as
git checkout master
git rebase origin/master
Rebasing
git checkout <featurebranch>
git rebase master
a32
2e2
8b3
Master/Trunk/MainLatest
Rebasing
e69
d19
Branch
a32
2e2
8b3
e69
d19
Branch
Master/Trunk/MainLatest
Rebase
Rebasing
a32
2e2
e69'
d19'
8b3 Branch
Master/Trunk/MainLatest
Rebasing
Rebase
a32
2e2
e69'
d19'
8b3 Branch
Master/Trunk/MainLatest
Merge
Rebasing
Rebasing
‣Rebase topic branch on master
Rebasing
Interactive rebasing
Rework your work so it

 makes sense to the team
Rebasing
Rebasing
git checkout myfeaturebranch
# Replay the last 5 commits
git rebase -i HEAD~5
a32
2e2
8b3
Master/Trunk/MainLatest
Rebasing
e69
d19
a32
2e2
Master/Trunk/MainLatest
Rebasing
e69
d19
a32
2e2
Master/Trunk/MainLatest
Rebasing
e69
d19
a32
2e2
Master/Trunk/MainLatest
Rebasing
e69
d19
a32
2e2
Master/Trunk/MainLatest
Rebasing
e69
d19
a32
2e2
Master/Trunk/MainLatest
Rebasing
e69
d19
a32
Master/Trunk/MainLatest
Rebasing
e69
d19
2e2
Rebasing
‣Interactively rebase a single branch
Workflows
Usage Models
Usage Models
Central
Repo
Centralized
Usage Models
Blessed
Repo
Dictatorship
Usage Models
Certified
Repo
Development Repo
ntegrationManaged
Continuous
Integration
Server
Usage Models
Custom+PublicContrib
Customized
PrivatePublic
GitHub
Usage Models
Mirror
Development Repo
Mirrored
Mirror
Certified
Repo
Undo
Clean
Clean
clean purges untracked files
respects ignored and tracked
Clean
# Dry-run remove files
git clean -n
Clean
# Dry-run remove files, dirs
git clean -nd
Clean
# Remove files
git clean -f
Clean
# Remove files, dirs
git clean -fd
Undo
‣Clean untracked files
Clean
# Also remove ignored files
git clean -xf
Clean
# Also remove ignored files, dirs
git clean -xdf
Clean
# Only list ignored files
git clean -Xn
Clean
# Only remove ignored files
git clean -Xf
Undo
‣Clean ignored files
Undo
Revert
Revert
revert negates one or more commits
Revert
new commit at the end of HEAD
Revert
no pointer to old ref in revert commit
Revert
comment references the old one
8b3 '
Revert
a32
2e2
d19'
8b3
Revert
a32
2e2
d19'
8b3
Revert
8b3 '
Revert
# Revert a single commit
git revert <ref>
Revert
‣Revert a single change
Revert
# Revert a range of commits
git revert <ref1>..<ref2>
Revert
# Revert a range of commits
git revert <old>..<new>
Revert
must have the old..new refs
in the right order
Undo
Amend
Amend
amend rewrites the last commit
Amend
git commit --amend
Amend
‣Amend a bad commit message
Amend
git add <missingfile>
git commit --amend
Amend
‣Amend a missing file
Git-SVN
Cloning
git-svn
‣Subversion protocol bridge from Git
‣Round-trip integration
‣Transactions in Git == transactions in SVN
git-svn
# Clone one branch
git svn clone <svnurl>
git-svn
# Clone all branches, tags
git svn clone --stdlayout <svnurl>
git-svn
‣Alternate conversion tool
‣ svn2git
‣ https://github.com/nirvdrum/svn2git
‣ Converts tags to Git tags
Git-SVN
Updating
git-svn
‣Fetch new changes
‣git svn rebase
git-svn
‣Send new changes
‣git svn dcommit
Git-SVN
SVN Externals
git-svn
‣ SVN Externals
‣ No direct support
‣ Represented as separate repos
‣ Git points at a stable snapshot
‣ SVN Extern...
git-svn
‣Externals cloning process
‣ svn propget svn:externals <MODULE>
‣ git svn clone --stdlayout <THEURL>
‣ git submodu...
git-svn
‣ SVN Externals helper script
‣ https://github.com/andrep/git-svn-clone-externals
Git FoundationsAn exploration of the Git toolbox
Officialtrainingcurriculumv3.1.0©2012,GitHub,Inc.
@matthewmccull
matthew@github.com
github.com/training
Credits
‣Images sourced from:
‣ AmbientIdeasPhotography.com
‣ Hand Tools
‣ Flickr Creative Commons
‣ Clock: http://www.flic...
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Upcoming SlideShare
Loading in...5
×

Github - Git Training Slides: Foundations

1,121

Published on

Slide deck with detailed step breakdown that explains how git works, together with simple examples that you can try out yourself. Slides originated from http://teach.github.com/articles/course-slides/

Author: https://twitter.com/matthewmccull

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,121
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
62
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Github - Git Training Slides: Foundations

  1. 1. Git FoundationsAn exploration of the Git toolbox Officialtrainingcurriculumv3.1.0©2012,GitHub,Inc.
  2. 2. Hello!
  3. 3. Matthew McCullough @matthewmccull
  4. 4. Ma hew who? ‣Open source contributor ‣Build tool book co-author ‣Continuous integration book co-author ‣5 year Git evangelist ‣VP of Training at GitHub
  5. 5. Welcome ‣Questions, Pacing ‣Ask questions at any time. Don't wait! ‣Suggest course pacing slowing/speeding up
  6. 6. Git Where’s this coming from?
  7. 7. Git
  8. 8. Git? Open Source
  9. 9. Git? bash scripts C code
  10. 10. Git? ≉
  11. 11. Git -noun British Slang. an unpleasant or contemptible person -Oxford English Dictionary “ ”
  12. 12. I'm an egotistical bastard, and I name all my projects after myself. First Linux, now git. -Linus Torvalds “ ”
  13. 13. Git What is this thing?
  14. 14. GIT - the stupid content tracker "git" can mean anything, depending on your mood. * random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant. * stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang. * "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room. * "goddamn idiotic truckload of sh*t": when it breaks Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals. Git is an Open Source project covered by the GNU General Public License. It was originally written by Linus Torvalds with help of a group of hackers around the net. It is currently maintained by Junio C Hamano. “ ”
  15. 15. file trackercontent
  16. 16. Git? centralized version control systems have matured
  17. 17. CVS Subversion PVCS Perforce Clear CaseSource Safe RCS Folders Git?
  18. 18. small improvements, but no radical innovation Git?
  19. 19. Linus? Git?
  20. 20. I did end up using CVS for 7 years at a commercial company and I hate it with a passion... The slogan of Subversion for a while was "CVS done right"... and if you start with that kind of slogan, there's nowhere you can go. There is no way to do CVS right. -Linus Torvalds “ ”
  21. 21. VCS reboot Git?
  22. 22. 50% Distributed Version Control Git? 50% Git Concepts with
  23. 23. 1997 code co-op
  24. 24. 2001 arch
  25. 25. 2003 monotone
  26. 26. 2003 SVK
  27. 27. 2003 darcs
  28. 28. 2005 bazaar
  29. 29. 2005 mercurial
  30. 30. 2005 git
  31. 31. time to mature
  32. 32. most unique improvements
  33. 33. largest DVCS user base
  34. 34. Setup Testing Git
  35. 35. Setting up Git Check your Git version... git --version
  36. 36. Setup What is a Git install?
  37. 37. Setting up Git binaries on your $PATH
  38. 38. Using Creating a repository
  39. 39. Creating A Repository # Green field project $ git init newproject $ cd newproject # ...start coding
  40. 40. Creating A Repository ‣Create our first repository
  41. 41. Creating A Repository or if you already have source code
  42. 42. Creating A Repository # Legacy project tree $ cd existingproject $ git init # Add all the code $ git add . $ git commit -m”Initial import”
  43. 43. Using What’s in .git?
  44. 44. Contents of .git .git !"" COMMIT_EDITMSG !"" HEAD !"" MERGE_RR !"" config !"" description !"" hooks #   !"" pre-commit.sample #   $"" update.sample !"" index !"" info #   $"" exclude !"" logs #   !"" HEAD #   $"" refs #   $"" heads #   $"" master !"" objects #   !"" 54 #   #   $"" 3b9bebdc6bd5c4b22136034a95dd097a57d3dd #   !"" info #   $"" pack !"" refs    !"" heads    #   $"" master    $"" tags
  45. 45. Three stage thinking ‣Explore the .git folder
  46. 46. Configuration Display
  47. 47. Configuring Git Query existing configuration
  48. 48. Configuring Git All entries
  49. 49. Configuring Git #List all config values git config --list
  50. 50. Configuring Git Single entry
  51. 51. Configuring Git #Query effective value of a single key git config section.key git config section.subsection.key
  52. 52. Configuring Git #Show a specific config value git config user.name git config user.email
  53. 53. Configuration Layers
  54. 54. Config Targets git config --system #Saves to /etc/gitconfig
  55. 55. Config Targets git config --global #Saves to ~/.gitconfig
  56. 56. Config Targets git config --local #Saves to .git/config
  57. 57. Configuring Git #Configure a setting in a .git repository git config __________ git config --local __________ #Configure a setting in the user's home dir git config --global __________ #Configure a setting in the Git install dir # e.g. /usr/local/Cellar/git/1.7.x/etc/gitconfig git config --system __________
  58. 58. Config Targets Git configuration reading & writing targets local by default
  59. 59. Configuration Inheritance
  60. 60. Config Inheritance Query existing configuration by layer
  61. 61. Config Inheritance #Query a single key in a single layer git config --<WHERE> section.key git config --<WHERE> section.subsection.key
  62. 62. Config Inheritance #List all system config values git config --system --list
  63. 63. Config Inheritance #List all global config values git config --global --list
  64. 64. Config Inheritance #List all local config values git config --local --list
  65. 65. Config Inheritance #List effective config values git config --list
  66. 66. Configuration Set user identity
  67. 67. Set User Identity any config at any layer
  68. 68. Set User Identity #List the current config git config --global user.name "Fird Birfle" git config --global user.email "fird@birfle.com"
  69. 69. Set User Identity just a string
  70. 70. Set User Identity user identity
  71. 71. Set User Identity user identityauthenticationnot
  72. 72. Set User Identity user identityauthenticationauthorizationnot
  73. 73. Configuration Display color
  74. 74. Set Console Color console color
  75. 75. Set Console Color git config --global color.ui always
  76. 76. Set Console Color git log --graph --decorate --simplify-by-decoration --abbrev-commit --date=relative --pretty=oneline --all
  77. 77. Configuring Git git log --graph --decorate --simplify-by-decoration --abbrev-commit --date=relative --pretty=oneline --all | more
  78. 78. Set Console Color Bleh!
  79. 79. Set Console Color output destination detection
  80. 80. Set Console Color git config --global color.ui auto # or the identical effect with... git config --global color.ui true
  81. 81. Set Console Color git log --graph --decorate --simplify-by-decoration --abbrev-commit --date=relative --pretty=oneline --all | more
  82. 82. Set Console Color when you need itColor
  83. 83. Set Console Color only when you need itColor
  84. 84. Configuration Line endings
  85. 85. Line Endings line endings
  86. 86. Line Endings VS
  87. 87. Line Endings VS LF CRLF
  88. 88. Line Endings default is to do nothing
  89. 89. Line Endings http://help.github.com/dealing-with-lineendings/
  90. 90. Line Endings #Force files to be LF in the repo, # even on Mac/Linux git config --global core.autocrlf input #Force Windows to convert to platform # on checkout and to LF on commit git config --global core.autocrlf true
  91. 91. Line Endings #Force files to be LF during `add` git config --global core.autocrlf input #Force Windows to convert to CRLF # on checkout and to LF on `add` git config --global core.autocrlf true
  92. 92. warn about conversion
  93. 93. Line Endings #Never complain about line ending conversion git config --global core.safecrlf false #Warn, but allow line ending conversion to proceed #(the default) git config --global core.safecrlf warn #Do not allow line ending conversion to proceed git config --global core.safecrlf true
  94. 94. Configuration Secure Sockets Host (SSH)
  95. 95. Configuring SSH ‣Generate an ssh key pair
  96. 96. Configuring SSH ssh key pair
  97. 97. Configuring SSH $ ssh-keygen -t rsa -C”For GitHub”
  98. 98. Configuring SSH $ ssh-keygen -t rsa -C”For GitHub”
  99. 99. Configuring SSH
  100. 100. Configuring SSH # Verify the files were created $ cd ~/.ssh $ ls
  101. 101. Configuring SSH
  102. 102. Configuring SSH ‣id_rsa is the private half of the key ‣Keep this uncompromisingly secret ‣id_rsa.pub is the public half of the key ‣Give this away freely
  103. 103. Configuring SSH #GitHub sanity test ssh -T git@github.com > Hi matthewmccullough! You've successfully authenticated, but GitHub does not provide shell access.
  104. 104. Configuring SSH #GitHub sanity test with verbose SSH ssh -v git@github.com >OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009 debug1: Reading configuration data /Users/mccm06/.ssh/config debug1: Reading configuration data /etc/ssh_config debug1: Connecting to github.com [207.97.227.239] port 22. debug1: Connection established. debug1: identity file /Users/mccm06/.ssh/identity type -1 debug1: identity file /Users/mccm06/.ssh/id_rsa type 1 debug1: identity file /Users/mccm06/.ssh/id_dsa type 2 ... debug1: Host 'github.com' is known and matches the RSA host key. debug1: Found key in /Users/mccm06/.ssh/known_hosts:3 debug1: ssh_rsa_verify: signature correct ... debug1: Trying private key: /Users/mccm06/.ssh/identity debug1: Offering public key: /Users/mccm06/.ssh/id_rsa debug1: Remote: Forced command: gerve matthewmccullough
  105. 105. Using Git Three Stage Thinking
  106. 106. Three stage thinking ‣Edit ‣Add ‣Commit
  107. 107. Three stage thinking Working Staging Repo add commit edit
  108. 108. Three stage thinking
  109. 109. ‣shopping cart ‣put things in ‣take things out ‣purchase at register
  110. 110. Three stage thinking
  111. 111. Three stage thinking ‣database transaction ‣update values ‣insert rows ‣delete rows ‣commit transaction
  112. 112. Three stage thinking only onestaging area
  113. 113. Three stage thinking Working Staging Repo add commit edit
  114. 114. Setup Commit Message Editor
  115. 115. Commit Message Editor
  116. 116. ✓? Used the VI editor?
  117. 117. Commit Message Editor I y ;WQ
  118. 118. Commit Message Editor an alternate editor?
  119. 119. Commit Message Editor $EDITOR environment variable O ption 1
  120. 120. Commit Message Editor $ export EDITOR=<AnEditorOnYourPath> O ption 1
  121. 121. Commit Message Editor GitPad wraps Notepad (or $EDITOR) O ption 2
  122. 122. Commit Message Editor http://github.com/github/GitPad O ption 2
  123. 123. Commit Message Editor Run GitPad ...registers & wraps Notepad as the editor O ption 2
  124. 124. Commit Message Editor Git-specific configuration option O ption 3
  125. 125. Commit Message Editor #for TextMate on Mac git config --global core.editor "mate -w" #for Notepad2 on Windows git config --global core.editor "notepad2.exe" #for emacs on Linux git config --global core.editor "emacs" O ption 3
  126. 126. Commit Message Editor O ption 3
  127. 127. Commit Message Editor ‣Toggle to alternate editor ‣Make a commit ‣Test that the new editor pops up
  128. 128. Usage Basics Adding & committing code
  129. 129. Three stage thinking $ vi first.html $ git status $ git add first.html $ git commit -m”First commit”
  130. 130. Three stage thinking ‣Write a sample HTML or TXT file ‣Inspect Git’s status ‣Add code (stage it) ‣Commit code
  131. 131. Usage Basics Diff-ing changes
  132. 132. Three stage thinking What has changed that we haven’t committed?
  133. 133. Three stage thinking # Show the unstaged changes $ git diff
  134. 134. Three stage thinking Working Staging Repo $ git diff
  135. 135. Three stage thinking # Show the staged changes $ git diff --staged
  136. 136. Three stage thinking Working Staging Repo $ git diff --staged
  137. 137. Three stage thinking # Show uncommitted changes $ git diff HEAD
  138. 138. Three stage thinking Working Staging Repo $ git diff HEAD
  139. 139. Usage Basics Limiting diff output
  140. 140. Limiting Diff Output Word changes instead of entire lines?
  141. 141. Limiting Diff Output git diff --color-words
  142. 142. Limiting Diff Output $ git diff diff --git a/first.txt b/first.txt index cbb1543..e99dea9 100644 --- a/first.txt +++ b/first.txt @@ -1,4 +1,4 @@ -//Round the rugged rock +//Round the ragged rock $ git diff --color-words diff --git a/first.txt b/first.txt index cbb1543..e99dea9 100644 --- a/first.txt +++ b/first.txt @@ -1,4 +1,4 @@ //Round the ruggedragged rock
  143. 143. Limiting Diff Output git diff --word-diff
  144. 144. Limiting Diff Output $ git diff diff --git a/first.txt b/first.txt index cbb1543..e99dea9 100644 --- a/first.txt +++ b/first.txt @@ -1,4 +1,4 @@ -//Round the rugged rock +//Round the ragged rock $ git diff --word-diff diff --git a/first.txt b/first.txt index cbb1543..e99dea9 100644 --- a/first.txt +++ b/first.txt @@ -1,4 +1,4 @@ //Round the [-rugged-]{+ragged+} rock
  145. 145. Usage Basics Whitespace diff
  146. 146. Limiting Diff Output whitespace suppressed?
  147. 147. Limiting Diff Output refactoring review
  148. 148. Limiting Diff Output git diff -w
  149. 149. Limiting Diff Output $ git diff diff --git a/first.txt b/first.txt index 09195c0..f2c3243 100644 --- a/first.txt +++ b/first.txt @@ -1,4 +1,4 @@ -//Foo -//Bar -//Baz + //Foo +// Bar +//Baz▊ $ git diff -w $
  150. 150. Usage Basics Limiting diff by type
  151. 151. Limiting Diff Output # Added (A) # Copied (C) # Deleted (D) # Modified (M) # Renamed (R) # Type changed (T) # Unmerged (U) # Unknown (X) # Pairing Broken (B) # Only show changes in added files git diff --diff-filter=A
  152. 152. Limiting Diff Output # Added (A) # Copied (C) # Deleted (D) # Modified (M) # Renamed (R) # Type changed (T) # Unmerged (U) # Unknown (X) # Pairing Broken (B) # Only show changes in modified files git diff --diff-filter=M
  153. 153. Limiting Diff Output # Added (A) # Copied (C) # Deleted (D) # Modified (M) # Renamed (R) # Type changed (T) # Unmerged (U) # Unknown (X) # Pairing Broken (B) # Only show changes in added or modified files git diff --diff-filter=AM
  154. 154. Limiting Diff Output $ git status -s -u D README MM first.txt $ git diff --diff-filter=M diff --git a/first.txt b/first.txt index 71b55ef..14e4853 100644 --- a/first.txt +++ b/first.txt @@ -1,3 +1,3 @@ -//Foo //Bar +//Baz Only first.txt is reported
  155. 155. Usage Basics Reviewing history
  156. 156. Three stage thinking view history of commits
  157. 157. Three stage thinking # Show all history git log
  158. 158. Three stage thinking # Show all history with filenames git log --stat
  159. 159. Three stage thinking # Show all history with patches git log --patch git log -p
  160. 160. Three stage thinking # Limit the output entries git log -1 git log -3 git log -5
  161. 161. Three stage thinking # Control the output format git log --pretty=full
  162. 162. Three stage thinking # Control the output format git log --pretty=fuller
  163. 163. Three stage thinking # Control the output format git log --pretty=email
  164. 164. Three stage thinking # Control the output format git log --pretty=raw
  165. 165. Three stage thinking # Control the output format git log --pretty=format:<pattern>
  166. 166. Three stage thinking # Limit the output to added files git log --diff-filter=A
  167. 167. Usage Basics+ Ignoring files
  168. 168. Ignoring Files Untracked Tracked Unmodified Tracked Modified Tracked Staged Ignored commit add edit add rm ignore
  169. 169. Ignoring Files suppressing files from being reported as untracked
  170. 170. Ignoring Files glob patterns
  171. 171. Ignoring Files $ vim .gitignore #Add glob patterns, one per line *.log *.tmp
  172. 172. Ignoring Files in-memory recursive evaluation
  173. 173. Ignoring Files $ vim .gitignore #Add glob patterns, one per line *.log *.tmp target output/ !special.log
  174. 174. Ignoring Files ‣Ignore files via local .gitignore
  175. 175. Usage Basics+ Open source .gitignores
  176. 176. Open Source Ignores Preconfigured .gitignore files
  177. 177. Open Source Ignores http://github.com/github/gitignore
  178. 178. copy and paste(the one time it’s OK to do it)
  179. 179. Usage Basics+ Global ignores
  180. 180. Global Ignore Global .gitignore ?
  181. 181. Global Ignore off by default
  182. 182. Global Ignore $ git config --global core.excludesfile "~/.gitignore"
  183. 183. Global Ignore $ vim ~/.gitignore # Operating system and editor temp files # Generally redundant over project .gitignores thumbs.db .DS_Store
  184. 184. Global Ignore ‣Ignore files via global ~/.gitignore
  185. 185. Usage Basics+ Removing files
  186. 186. The Git File Workflow Untracked Tracked Unmodified Tracked Modified Tracked Staged Ignored commit add edit add rm ignore
  187. 187. The Git File Workflow Removing Files
  188. 188. The Git File Workflow # Directly remove & stage $ git rm <FILENAME>
  189. 189. The Git File Workflow # Remove with OS or tool, # not integrated with Git $ rm <FILENAME> # Staging area says it is # deleted but not staged $ git status # Put deletion into staging $ git rm <FILENAME>
  190. 190. The Git File Workflow # Remove with OS or tool # then follow up with git add $ rm <FILENAMES> $ git add -u .
  191. 191. The Git File Workflow ‣ Remove files
  192. 192. Usage Basics+ Moving files
  193. 193. The Git File Workflow Untracked Tracked Unmodified Tracked Modified Tracked Staged Ignored commit add edit add rm ignore
  194. 194. The Git File Workflow Moving Files
  195. 195. The Git File Workflow # Directly move & stage $ git mv <FILENAME> <NEWFILENAME>
  196. 196. The Git File Workflow # Move with OS or tool, mv <FILENAME> <NEWFILENAME> # Then follow up with git add git add -A .
  197. 197. The Git File Workflow ‣ Rename (move) files ‣ View history of the move
  198. 198. Usage Basics+ Similarity index
  199. 199. Similarity Index no "move" primitive
  200. 200. Similarity Index “similarity index”
  201. 201. Similarity Index score of sameness
  202. 202. Usage Basics+ Similarity index for moves
  203. 203. Similarity Index # Move with OS or tool, $ mv <FILENAME> <NEWFILENAME> # Follow up by staging everything $ git add -A . # Renames showing git status # No renames showing? git log --stat
  204. 204. why no renames in history?
  205. 205. Similarity Index # Renames shown git log --stat -M
  206. 206. Similarity Index ‣ Rename (move) files with changes ‣ Essentially, a refactoring workflow
  207. 207. Usage Basics+ Similarity index for copies
  208. 208. Similarity Index # Copies & renames shown # (superset of -M) git log --stat -C
  209. 209. Similarity Index ‣Copy a file to a new filename ‣Add and commit it ‣Log it using our -C option
  210. 210. “For performance reasons, by default, -C option finds copies only if the original file of the copy was modified in the same changeset. ”
  211. 211. Similarity Index ‣Modify a file and copy it (in the same commit) ‣Log using the -C option
  212. 212. “The --find-copies-harder flag makes the command inspect unmodified files as candidates for the source of copy. This is a very expensive operation for large projects, so use it with caution. Giving more than one -C option has the same effect. ”
  213. 213. Similarity Index # Copies & renames shown # (superset of -M) git log --stat -C -C git log --stat --find-copies-harder
  214. 214. Similarity Index ‣Log the same file using our -C -C option
  215. 215. Usage Basics+ Similarity index for blame
  216. 216. Similarity Index # File authoring shown git blame rerere.c
  217. 217. Similarity Index # True source of code shown git blame rerere.c -C
  218. 218. Similarity Index 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 1) #include "cache.h" c455c87c (Johannes Schindelin 2008-07-21 19:03:49 +0100 2) #include "string-list.h" 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 3) #include "rerere.h" 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 4) #include "xdiff-interface.h" dea4562b (Junio C Hamano 2009-12-25 15:51:32 -0800 5) #include "dir.h" dea4562b (Junio C Hamano 2009-12-25 15:51:32 -0800 6) #include "resolve-undo.h" dea4562b (Junio C Hamano 2009-12-25 15:51:32 -0800 7) #include "ll-merge.h" 8588567c (Junio C Hamano 2010-01-16 23:28:46 -0800 8) #include "attr.h" 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 9) ac49f5ca (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 10) #define RESOLVED 0 ac49f5ca (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 11) #define PUNTED 1 ac49f5ca (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 12) #define THREE_STAGED 2 ac49f5ca (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 13) void *RERERE_RESOLVED = &RERERE_RESOLVED; ac49f5ca (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 14) 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 15) /* if rerere_enabled == -1, fall back to detection of .git 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 16) static int rerere_enabled = -1; 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 17) 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 18) /* automatically update cleanly resolved paths to the inde 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 19) static int rerere_autoupdate; 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 20) 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 21) static char *merge_rr_path; 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 22) 90056966 (SZEDER Gábor 2009-02-14 23:21:04 +0100 23) const char *rerere_path(const char *hex, const char *file) 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 24) { 90056966 (SZEDER Gábor 2009-02-14 23:21:04 +0100 25) return git_path("rr-cache/%s/%s", hex, file); 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 26) } 5b2fd956 (Stephan Beyer 2008-07-09 14:58:57 +0200 27)
  219. 219. Similarity Index 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 1) #include "cache.h" c455c87c rerere.c (Johannes Schindelin 2008-07-21 19:03:49 +0100 2) #include "string-list.h" 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 3) #include "rerere.h" 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 4) #include "xdiff-interface.h" dea4562b rerere.c (Junio C Hamano 2009-12-25 15:51:32 -0800 5) #include "dir.h" dea4562b rerere.c (Junio C Hamano 2009-12-25 15:51:32 -0800 6) #include "resolve-undo.h" dea4562b rerere.c (Junio C Hamano 2009-12-25 15:51:32 -0800 7) #include "ll-merge.h" 8588567c rerere.c (Junio C Hamano 2010-01-16 23:28:46 -0800 8) #include "attr.h" 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 9) ac49f5ca rerere.c (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 10) #define RESOLVED 0 ac49f5ca rerere.c (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 11) #define PUNTED 1 ac49f5ca rerere.c (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 12) #define THREE_STAGED 2 ac49f5ca rerere.c (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 13) void *RERERE_RESOLVED = &RERERE_RESOLVED; ac49f5ca rerere.c (Martin von Zweigbergk 2011-02-16 05:47:44 -0500 14) b4372ef1 builtin-rerere.c (Johannes Schindelin 2007-07-06 13:05:59 +0100 15) /* if rerere_enabled == -1, fall back to detection of .git b4372ef1 builtin-rerere.c (Johannes Schindelin 2007-07-06 13:05:59 +0100 16) static int rerere_enabled = -1; b4372ef1 builtin-rerere.c (Johannes Schindelin 2007-07-06 13:05:59 +0100 17) 121c813f builtin-rerere.c (Junio C Hamano 2008-06-22 02:04:31 -0700 18) /* automatically update cleanly resolved paths to the inde 121c813f builtin-rerere.c (Junio C Hamano 2008-06-22 02:04:31 -0700 19) static int rerere_autoupdate; 121c813f builtin-rerere.c (Junio C Hamano 2008-06-22 02:04:31 -0700 20) 658f3650 builtin-rerere.c (Johannes Schindelin 2006-12-20 17:39:41 +0100 21) static char *merge_rr_path; 658f3650 builtin-rerere.c (Johannes Schindelin 2006-12-20 17:39:41 +0100 22) 90056966 rerere.c (SZEDER Gábor 2009-02-14 23:21:04 +0100 23) const char *rerere_path(const char *hex, const char *file) 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 24) { 90056966 rerere.c (SZEDER Gábor 2009-02-14 23:21:04 +0100 25) return git_path("rr-cache/%s/%s", hex, file); 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 26) } 5b2fd956 rerere.c (Stephan Beyer 2008-07-09 14:58:57 +0200 27)
  220. 220. Network Offline design
  221. 221. Offline ‣Local repository is a full copy of the remote ‣Clone fetches all branches and tags ‣Almost all activities happen offline (local disk) ‣Offline activities are push-ed to remotes
  222. 222. More available connectivity
  223. 223. More demand to work without connectivity?
  224. 224. Offline nice benefit, but wrong reason
  225. 225. Offline batched network access
  226. 226. Offline
  227. 227. Offline Checkout a branch Add changes Commit changes Branch changes Log history Grep history Stash pending changes Tag a commit Remove a file Merge a branch Rewrite history
  228. 228. Offline give up incremental revision numbers
  229. 229. Offline ‣ Using every command offline
  230. 230. Network Cloning protocols
  231. 231. Cloning Repositories ‣Git supports many cloning protocols ‣file ‣git ‣ssh ‣http
  232. 232. Cloning Repositories ‣file ‣git clone file://myrepos/project ‣git clone /myrepos/project
  233. 233. Cloning Repositories ‣git ‣git clone git://server/project.git
  234. 234. Cloning Repositories ‣ssh ‣ git clone git+ssh://user@server:project.git ‣ git clone user@server:project.git
  235. 235. Cloning Repositories ‣http (dumb) ‣git clone http://server/project.git ‣git clone https://server/project.git
  236. 236. Cloning Repositories ‣http (smart) ‣git clone http://server/project.git ‣git clone https://server/project.git
  237. 237. Cloning Repositories ‣ Clone hellogitworld ‣ git clone
  238. 238. Network Proxy servers
  239. 239. Cloning Repositories ‣Git Configuration ‣git config --global http.proxy “<URL>”
  240. 240. Network Speed
  241. 241. ‣git: git ‣hg: mercurial ‣bzr: bazaar
  242. 242. data from http://whygitisbetterthanx.com/#git-is-fast git svn Init git svn Status git svn Diff git svn Tag git svn Log git svn Commit (Lg) git svn Commit (Sm) git c svn c Branch Speed
  243. 243. Speed ‣ Add, commit and push 1000 files
  244. 244. Network Namespaces
  245. 245. Namespaces Local Remote Upstream
  246. 246. Namespaces #List local branches git branch
  247. 247. Namespaces Local Remote Upstream
  248. 248. Namespaces #List remote branches git branch -r
  249. 249. Namespaces Local Remote Upstream
  250. 250. Namespaces #List all branches git branch -a
  251. 251. Namespaces Local Remote Upstream
  252. 252. Namespaces #List upstream branches git ls-remote origin
  253. 253. Namespaces Local Remote Upstream
  254. 254. Network Namespace operations
  255. 255. Namespaces Local Remote Upstream commit fetch push clone clone clone push pull pull pull
  256. 256. Network The commit lifecycle
  257. 257. Namespaces Commit Push Pull
  258. 258. Namespaces ‣git commit ‣Transactionally save code snapshot ‣Commit to local branch ‣Operate on local disk
  259. 259. Namespaces Commit Push Pull
  260. 260. Namespaces ‣git push <remote> ‣Send code to an upstream server ‣Update remote branches
  261. 261. Namespaces Commit Push Pull
  262. 262. Namespaces ‣git pull <remote> ‣Retrieve upstream objects ‣Update remote branch ‣Merge changes into local branch ‣Commit the merge to the local branch
  263. 263. Namespaces Local Remote Upstream commit fetch push clone clone clone push pull pull pull
  264. 264. Network Remotes
  265. 265. Remotes Remotes are just symbolic names
  266. 266. Remotes You can have as many as you like
  267. 267. Remotes The default name is origin if you’ve cloned
  268. 268. Remotes Remote-tracking branches are locally immutable (conceptually)
  269. 269. Remotes Local Remote Upstream
  270. 270. Remotes ‣ Adding remotes ‣ Fetching from remotes (upstream)
  271. 271. Network Pruning deletions
  272. 272. ‣ Purge remote branches that have been removed from an upstream repository ‣git remote prune <REMOTENAME>
  273. 273. Remotes ‣Deleting upstream branches ‣Pruning locally
  274. 274. Architecture Plumbing and Porcelain
  275. 275. Plumbing and Porcelain Command Composition
  276. 276. Plumbing is the set of low level utilities Command Composition
  277. 277. Porcelain is the set of end user commands Command Composition
  278. 278. Porcelain is comprised of plumbing Command Composition
  279. 279. Command Composition
  280. 280. git-add git-am git-archive git-bisect git-branch git-bundle git- checkout git-cherry-pick git-citool git-clean git-clone git-commit git-describe git-diff git-fetch git-format-patch git-gc git-grep git- gui git-init git-log git-merge git-mv git-notes git-pull git-push git- rebase git-reset git-revert git-rm git-shortlog git-show git-stash git-status git-submodule git-tag gitk git-config git-fast-export git- fast-import git-filter-branch git-lost-found git-mergetool git-pack- refs git-prune git-reflog git-relink git-remote git-repack git-replace git-repo-config git-annotate git-blame git-cherry git-count-objects git-difftool git-fsck git-get-tar-commit-id git-help git-instaweb git- merge-tree git-rerere git-rev-parse git-show-branch git-verify-tag git-whatchanged git-archimport git-cvsexportcommit git-cvsimport git- cvsserver git-imap-send git-quiltimport git-request-pull git-send- email git-svn Porcelain git-apply git-checkout-index git-commit-tree git-hash-object git-index-pack git-merge-file git-merge-index git-mktag git-mktree git-pack-objects git-prune-packed git-read-tree git- symbolic-ref git-unpack-objects git-update-index git-update-ref git-write-tree git-cat-file git-diff-files git-diff-index git-diff-tree git-for-each-ref git-ls-files git-ls-remote git- ls-tree git-merge-base git-name-rev git-pack-redundant git-rev-list git-show-index git-show- ref git-tar-tree git-unpack-file git-var git-verify-pack git-daemon git-fetch-pack git-http- backend git-send-pack git-update-server-info git-http-fetch git-http-push git-parse-remote git-receive-pack git-shell git-upload-archive git-upload-pack git-check-attr git-check-ref- format git-fmt-merge-msg git-mailinfo git-mailsplit git-merge-one-file git-patch-id git-peek- remote git-sh-setup git-stripspace Plumbing
  281. 281. pull is comprised of fetch + merge Command Composition
  282. 282. checkout -b is comprised of branch + checkout Command Composition
  283. 283. log HEAD is comprised of rev-parse + log Command Composition
  284. 284. Aliases Command shortcuts
  285. 285. Aliases ‣Shortcuts for common commands ‣Create your own recipe ‣Largely the same as shell aliases
  286. 286. Aliases # Alias for status as 's' git config --global alias.s "status -u -s"
  287. 287. Aliases ‣ Add an alias
  288. 288. Aliases # Alias for log with file name as 'l' git config --global alias.l "log --stat -C"
  289. 289. Aliases # Alias showing all branches to 'br' git config --global alias.br "branch -a"
  290. 290. Aliases # Alias for commit-no-staging to 'cns' git config --global alias.cns "commit -a"
  291. 291. Aliases # Alias for shell pull then push to 'sync' $ git config --global alias.sync "!git pull && git push"
  292. 292. Aliases # Alias for crummy-commit-file-quick $ git config --global alias.ccfq "!sh -c 'git add $1 && git commit -m"Placeholder"' -"
  293. 293. Aliases ‣ Matthew's Aliases ‣ https://github.com/matthewmccullough/git-workshop/blob/master/ workbook/examples/config/.gitconfig
  294. 294. Architecture Storage
  295. 295. Typical SCMs use delta storage Storage
  296. 296. CVS / Subversion / darcs / Mercurial Storage
  297. 297. Storage v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File BFile B Δ Δ Δ Δ ΔΔΔ
  298. 298. Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Checkin Delta storage gets slower as the history of a file gets longer Storage
  299. 299. Git uses DAG storage Storage
  300. 300. Directed Acyclic Graph Storage
  301. 301. Storage
  302. 302. Copy of the entire tree per checkin Storage
  303. 303. cp -r srcfolder srcfolder.prev Storage
  304. 304. Why? Storage
  305. 305. Storage v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File BFile B File A File A File C File C File C
  306. 306. hard link to existing identical blobs Storage
  307. 307. Storage v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File BFile B File A File A File C File C File Cß
  308. 308. zlib deflates each blob at commit Storage
  309. 309. Storage v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File BFile B File A File A File C File C File C
  310. 310. zlib deflates the entire repo Storage
  311. 311. Storage v1 v2 v3 v4 File A File B File C File A File B File B File C v5 File A File BFile B File A File A File C File C File C
  312. 312. Storage 2100 MBbecame 205 MB Act I
  313. 313. Architecture Hashes
  314. 314. Hashes centralized VCSs use sequential revision numbers
  315. 315. Hashes Git uses a SHA-1 hash
  316. 316. Hashes
  317. 317. 40 hex characters (20 bytes) Hashes
  318. 318. 9AB223D28B1AA46EF1780B22F304982E39872C34 Hashes
  319. 319. Hashes 9AB223D28B1AA46EF1780B22F304982E39872C34 <html> <body> <p>This is a test</p> <img src="http://ai.com/icon.gif"> </body> </html> 9AB223D28B1AA46EF1780B22F304982E39872C34
  320. 320. use as little of it as is unique Hashes
  321. 321. Architecture Hash shortcuts
  322. 322. commitish & treeish Hashes
  323. 323. commitish Hashes = shorthand for commit hashes
  324. 324. treeish Hashes = shorthand for tree hashes
  325. 325. 9AB22F a certain commit Hashes
  326. 326. 9AB22F^ one commit before a certain commit Hashes
  327. 327. 9AB22F^^ two commits before a certain commit Hashes
  328. 328. 9AB22F~5 five commits before a certain commit Hashes
  329. 329. 9AB223..56CD77 between these two commits Hashes
  330. 330. HEAD the most recent commit on this branch Hashes
  331. 331. HEAD^ one commit before the most recent commit Hashes
  332. 332. HEAD~2 two commits before the most recent commit Hashes
  333. 333. HEAD..HEAD^^^ between the given recent commits Hashes
  334. 334. master the most recent commit on this branch Hashes
  335. 335. master^^ two commits before the most recent commit on this branch Hashes
  336. 336. master~5 five commits before the most recent commit on this branch Hashes
  337. 337. remotes/origin/master the most recent commit on this remote tracking branch Hashes
  338. 338. origin/master the most recent commit on this remote tracking branch Hashes
  339. 339. Hashes Navigate with commitish on commit, status, & log
  340. 340. Architecture Hash relationships
  341. 341. Hashes ‣Blob ‣Tree ‣Commit ‣Tag
  342. 342. Hashes tree tree: 7e8b1 web blob: 9ab16 index.html a10b3 tree blob: 8d162 logo.jpg blob: 51d22 draw.js 7e8b1commit tree: a10b3 parent: nil author: Fird committer: Matthew message: Major refactoring of the web content. c67db blob<html> <body></body> </html> 9ab16 blob //Some more javascript var renderSize 51d22 blob 7D 8D B3 7F BD 12 9F E9 7B 78 9D 3F 5C A6 72 CB 8d162
  343. 343. Hashes v1 v2 v3 commit tree: 9a87b parent: nil author: Fird committer: Matthew message: Major refactoring of the Javascript rendering engine. c67db commit tree: b22c1 parent: c67db author: Tim committer: Fird message: Minor update to HTML 9bd21 commit tree: b22c1 parent: 9bd21 author: Johnny committer: Joe message: New language transations 1c2d7
  344. 344. Hashes RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1
  345. 345. Branching Creating branches
  346. 346. Branches default branch name is master
  347. 347. Branches master doesn’t have any special privileges
  348. 348. Branches Local Remote Upstream
  349. 349. Branches # Creating a branch git branch <BRANCHNAME>
  350. 350. RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1
  351. 351. Hashes ‣Create a new local branch from HEAD
  352. 352. Branches # Creating a branch git branch <BRANCHNAME> HEAD
  353. 353. Branches # Creating a branch git branch <BRANCHNAME> <REF>
  354. 354. RELEASE_1.0 HEAD bug979branch commit c67db commit 9bd21 commit 1c2d7 commit 8c2d1 commit 1bdcd commit 2daa1
  355. 355. Hashes ‣Create a new local branch from a branch
  356. 356. Branching Branch as experiments
  357. 357. Branches What do cheap branches enable?
  358. 358. Branches ‣Experimentation ‣
  359. 359. Branches ‣Experimentation ‣Safe experimentation
  360. 360. Branches Better reuse of units of work
  361. 361. Hashes ‣Create a branch for an experiment ‣Delete the failed experiment
  362. 362. Branching Branch frequency
  363. 363. Branches When should you branch?
  364. 364. Branches The answer is always
  365. 365. Branches Branches isolate volatile work
  366. 366. Branches Branches cost a mere 20 bytes
  367. 367. Branches We’ve always wanted to branch often It’s just been too expensive, polluting, or ceremonious
  368. 368. Hashes ‣Show branches on the Git project
  369. 369. Branching Branch lifetimes
  370. 370. Branches ‣Branched by lifetime ‣ Product ‣ Integration ‣ Feature ‣ Story ‣ Idea
  371. 371. Branches product integration feature story idea
  372. 372. product v1.0 integration story1 story2 v1.5 integration story3 Branches
  373. 373. Branches Local Remote Upstream Integ Product Integ Product Integ Product
  374. 374. Branches Local Remote Upstream Idea Story Feature FeatureFeature Integ Product Integ Product Integ Product
  375. 375. Branches Local Remote Upstream Idea Story Feature FeatureFeature Integ Product Integ Product Integ Product
  376. 376. Branches ‣Branch from the master branch ‣Merge from the topic branch ‣Destroy the topic branch
  377. 377. Branching Stashes
  378. 378. Stash super quick branch
  379. 379. Stash local-only branch
  380. 380. Stash ‣Numbered branch ‣Stack based implementation ‣Push, Peek, and Pop operations (But has direct entry access too)
  381. 381. Stash creating a stash
  382. 382. Stash # Stash your pending changes git stash
  383. 383. Stash inspecting the stash
  384. 384. Stash # List your stashes git stash list
  385. 385. Stash noting the stash
  386. 386. Stash # Stash your pending changes git stash save “<Message>”
  387. 387. Stash # List your stashes git stash list
  388. 388. Stash using the stash
  389. 389. Stash # Merge & delete the latest stash git stash pop
  390. 390. Stash # Merge & delete a stash git stash pop stash@{0}
  391. 391. Stash # Merge & keep the latest stash git stash apply
  392. 392. Branches ‣Stash modified changes ‣Stash staged changes ‣Apply stashed changes
  393. 393. Stash converting a stash
  394. 394. Stash # Convert a stash to a branch git stash branch <newbr>
  395. 395. Stash # Convert a stash to a branch git stash branch <newbr> stash@{3}
  396. 396. Branches ‣Convert a stash to a branch
  397. 397. Tagging Tag uses
  398. 398. tags as a first class data type
  399. 399. taggingas a cheap operation
  400. 400. New ways to use tags?
  401. 401. Tagging ‣Tagging at each level of approval ‣Dev ‣CM ‣QA ‣Production
  402. 402. Tagging Tag types
  403. 403. Tagging reference, annotated and signed tag types
  404. 404. Tagging Reference tag
  405. 405. Tagging reference tag...
  406. 406. Tagging # Tag HEAD git tag <TAGNAME>
  407. 407. Tagging # Tag an existing ref git tag <TAGNAME> <REF>
  408. 408. Tagging # List known tags git tag
  409. 409. Tagging # Show a tag’s contents git show tag
  410. 410. Tagging ‣Tag a revision ‣Start a branch from a tag
  411. 411. Tagging Annotated tag
  412. 412. Tagging annotated tag...
  413. 413. Tagging git tag -a <TAGNAME>
  414. 414. Tagging git show <TAGNAME>
  415. 415. Tagging ‣Tag a revision with an annotated tag
  416. 416. Tagging Signed tag
  417. 417. Tagging signed tag...
  418. 418. Tagging git tag -s <TAGNAME>
  419. 419. Tagging git show <TAGNAME>
  420. 420. Tagging ‣Tag a revision with a signed tag
  421. 421. Tagging Transmitting tags
  422. 422. Tagging Tags don't push by default
  423. 423. Tagging # Push all tags git push <remote> <tag>
  424. 424. Tagging # Push all tags git push --tags
  425. 425. ‣Push a specific tag ‣Push all tags
  426. 426. Tagging Tags do fetch by default
  427. 427. ‣Fetch all tags
  428. 428. Tagging but the refspec doesn’t say to
  429. 429. ‣Inspect .git/config refspec
  430. 430. Merging The basics
  431. 431. Merging very traditional merge of a branch
  432. 432. Merging git checkout master git merge <featurebranch>
  433. 433. a32 2e2 e69 d19 8b3 Branch Master/Trunk/MainLatest Merging Recursive Merge 9f1 Mergee698b3
  434. 434. strategy: recursive result: no conflicts
  435. 435. a32 e69 d19 Branch Master/Trunk/MainLatest Merging Fast Forward Merge Merge
  436. 436. a32 e69 d19 Master/Trunk/MainLatest Merging FF Merge
  437. 437. strategy: recursive result: fast forward
  438. 438. a32 2e2 e69 d19 8b3 Branch Master/Trunk/MainLatest Merging Conflicting Merge Merge 9f1 e698b3 Fix Conflict
  439. 439. strategy: recursive result: conflicting
  440. 440. Merging Octopus
  441. 441. Merging git checkout master git merge <fb1> <fb2> <fb3>
  442. 442. strategy: octopus
  443. 443. Merging Subtree
  444. 444. Merging git checkout master git merge -s subtree <fb1>
  445. 445. Merging git checkout master git merge --squash -s subtree <fb1>
  446. 446. strategy: subtree
  447. 447. Tagging ‣Merge a local branch ‣Merge a remote branch
  448. 448. Rebasing What is rebasing?
  449. 449. rebasing is not a merge Rebasing
  450. 450. rebasing is a preparation for a merge Rebasing
  451. 451. Merges weave multiple old changes into a new unifying commit Rebasing
  452. 452. Rebase reorders the chosen commits before your branch work Rebasing
  453. 453. simulates team members taking turns working (one person at a time) Rebasing
  454. 454. Rebasing Rebasing on a branch
  455. 455. Rebasing git pull --rebase
  456. 456. Retrieve upstream changes and relocate your local changes to the end Rebasing
  457. 457. Rebasing git pull --rebase # is the same as git checkout master git rebase origin/master
  458. 458. Rebasing git checkout <featurebranch> git rebase master
  459. 459. a32 2e2 8b3 Master/Trunk/MainLatest Rebasing e69 d19 Branch
  460. 460. a32 2e2 8b3 e69 d19 Branch Master/Trunk/MainLatest Rebase Rebasing
  461. 461. a32 2e2 e69' d19' 8b3 Branch Master/Trunk/MainLatest Rebasing Rebase
  462. 462. a32 2e2 e69' d19' 8b3 Branch Master/Trunk/MainLatest Merge Rebasing
  463. 463. Rebasing ‣Rebase topic branch on master
  464. 464. Rebasing Interactive rebasing
  465. 465. Rework your work so it makes sense to the team Rebasing
  466. 466. Rebasing git checkout myfeaturebranch # Replay the last 5 commits git rebase -i HEAD~5
  467. 467. a32 2e2 8b3 Master/Trunk/MainLatest Rebasing e69 d19
  468. 468. a32 2e2 Master/Trunk/MainLatest Rebasing e69 d19
  469. 469. a32 2e2 Master/Trunk/MainLatest Rebasing e69 d19
  470. 470. a32 2e2 Master/Trunk/MainLatest Rebasing e69 d19
  471. 471. a32 2e2 Master/Trunk/MainLatest Rebasing e69 d19
  472. 472. a32 2e2 Master/Trunk/MainLatest Rebasing e69 d19
  473. 473. a32 Master/Trunk/MainLatest Rebasing e69 d19 2e2
  474. 474. Rebasing ‣Interactively rebase a single branch
  475. 475. Workflows Usage Models
  476. 476. Usage Models Central Repo Centralized
  477. 477. Usage Models Blessed Repo Dictatorship
  478. 478. Usage Models Certified Repo Development Repo ntegrationManaged Continuous Integration Server
  479. 479. Usage Models Custom+PublicContrib Customized PrivatePublic GitHub
  480. 480. Usage Models Mirror Development Repo Mirrored Mirror Certified Repo
  481. 481. Undo Clean
  482. 482. Clean clean purges untracked files respects ignored and tracked
  483. 483. Clean # Dry-run remove files git clean -n
  484. 484. Clean # Dry-run remove files, dirs git clean -nd
  485. 485. Clean # Remove files git clean -f
  486. 486. Clean # Remove files, dirs git clean -fd
  487. 487. Undo ‣Clean untracked files
  488. 488. Clean # Also remove ignored files git clean -xf
  489. 489. Clean # Also remove ignored files, dirs git clean -xdf
  490. 490. Clean # Only list ignored files git clean -Xn
  491. 491. Clean # Only remove ignored files git clean -Xf
  492. 492. Undo ‣Clean ignored files
  493. 493. Undo Revert
  494. 494. Revert revert negates one or more commits
  495. 495. Revert new commit at the end of HEAD
  496. 496. Revert no pointer to old ref in revert commit
  497. 497. Revert comment references the old one
  498. 498. 8b3 ' Revert a32 2e2 d19' 8b3
  499. 499. Revert a32 2e2 d19' 8b3 Revert 8b3 '
  500. 500. Revert # Revert a single commit git revert <ref>
  501. 501. Revert ‣Revert a single change
  502. 502. Revert # Revert a range of commits git revert <ref1>..<ref2>
  503. 503. Revert # Revert a range of commits git revert <old>..<new>
  504. 504. Revert must have the old..new refs in the right order
  505. 505. Undo Amend
  506. 506. Amend amend rewrites the last commit
  507. 507. Amend git commit --amend
  508. 508. Amend ‣Amend a bad commit message
  509. 509. Amend git add <missingfile> git commit --amend
  510. 510. Amend ‣Amend a missing file
  511. 511. Git-SVN Cloning
  512. 512. git-svn ‣Subversion protocol bridge from Git ‣Round-trip integration ‣Transactions in Git == transactions in SVN
  513. 513. git-svn # Clone one branch git svn clone <svnurl>
  514. 514. git-svn # Clone all branches, tags git svn clone --stdlayout <svnurl>
  515. 515. git-svn ‣Alternate conversion tool ‣ svn2git ‣ https://github.com/nirvdrum/svn2git ‣ Converts tags to Git tags
  516. 516. Git-SVN Updating
  517. 517. git-svn ‣Fetch new changes ‣git svn rebase
  518. 518. git-svn ‣Send new changes ‣git svn dcommit
  519. 519. Git-SVN SVN Externals
  520. 520. git-svn ‣ SVN Externals ‣ No direct support ‣ Represented as separate repos ‣ Git points at a stable snapshot ‣ SVN Externals follow changes on a branch
  521. 521. git-svn ‣Externals cloning process ‣ svn propget svn:externals <MODULE> ‣ git svn clone --stdlayout <THEURL> ‣ git submodule add <THESUBFOLDER> ‣ git submodule init ‣ git submodule update
  522. 522. git-svn ‣ SVN Externals helper script ‣ https://github.com/andrep/git-svn-clone-externals
  523. 523. Git FoundationsAn exploration of the Git toolbox Officialtrainingcurriculumv3.1.0©2012,GitHub,Inc.
  524. 524. @matthewmccull matthew@github.com github.com/training
  525. 525. Credits ‣Images sourced from: ‣ AmbientIdeasPhotography.com ‣ Hand Tools ‣ Flickr Creative Commons ‣ Clock: http://www.flickr.com/photos/7729940@N06/4019157830 ‣ Wikipedia ‣ Linus Torvalds: http://en.wikipedia.org/wiki/File:Linus_Torvalds.jpeg
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×