SlideShare uma empresa Scribd logo
1 de 263
1
© 2016 Brent Laster
1
© 2016 Brent Laster@BrentCLaster
Advanced Git:
Functionality and Features
Open Source 101 Conference
February 4, 2017
Brent Laster (author of Professional Git)
2
© 2016 Brent Laster
2
@BrentCLaster
About me
 Senior Manager, R&D at SAS in Cary, NC
 Global Trainer and Speaker
 Git, Gerrit, Gradle, Jenkins, Pipelines
 Author - NFJS magazine, Professional Git book
 LinkedIn https://www.linkedin.com/in/brentlaster
 Twitter @BrentCLaster
3
© 2016 Brent Laster
3
@BrentCLaster
Professional Git
 Available on:
 Amazon.com
 Wiley.com
4
© 2016 Brent Laster
4
@BrentCLaster
Agenda
 Core concepts refresh
 Merging and Rebasing
 Stash
 Reset and Revert
 Rerere
 Bisect
 Worktrees
 Submodules
 Subtrees
 Interactive Rebase
 Notes
 Grep
5
© 2016 Brent Laster
Check Out
Commit
C
h
e
k
o
u
t
C
h
e
c
k
o
u
t
C
o
m
m
i
t
Clone
Remote
Repository
Local
Environment
Central
Server
Local
Machine
Centralized Version Control Model Distributed Version Control Model
Centralized vs. Distributed VCS
6
© 2016 Brent Laster
6
@BrentCLaster
Git in One Picture
Dev
Prod
Public
Test
7
© 2016 Brent Laster
7
@BrentCLaster
Git in One Picture
Working DirectoryDev
Prod
Public
Test
8
© 2016 Brent Laster
8
@BrentCLaster
Git in One Picture
Staging Area
Working DirectoryDev
Prod
Public
Test
9
© 2016 Brent Laster
9
@BrentCLaster
Git in One Picture
Staging Area
Local Repository
Working DirectoryDev
Prod
Public
Test
10
© 2016 Brent Laster
10
@BrentCLaster
Git in One Picture
Staging Area
Local Repository
Working DirectoryDev
Prod
Public
Test
11
© 2016 Brent Laster
11
@BrentCLaster
Git in One Picture
Staging Area
Local Repository
Working DirectoryDev
Prod
Public
Test
Local Machine
12
© 2016 Brent Laster
12
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Local Machine
13
© 2016 Brent Laster
13
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Local Machine
14
© 2016 Brent Laster
14
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Local Machine
15
© 2016 Brent Laster
15
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Local Machine
16
© 2016 Brent Laster
16
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Local Machine
17
© 2016 Brent Laster
17
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Local Machine
18
© 2016 Brent Laster
18
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Commit
Local Machine
19
© 2016 Brent Laster
19
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
Server
Add
Commit
Local Machine
20
© 2016 Brent Laster
20
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Local Machine
21
© 2016 Brent Laster
21
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Local Machine
22
© 2016 Brent Laster
22
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push
Local Machine
23
© 2016 Brent Laster
23
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push
Local Machine
24
© 2016 Brent Laster
24
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push Clone
Local Machine
25
© 2016 Brent Laster
25
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push Clone
Local Machine
26
© 2016 Brent Laster
26
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push Clone
Local Machine
F
e
t
c
h
27
© 2016 Brent Laster
27
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working DirectoryDev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push Clone
Local Machine
F
e
t
c
h
28
© 2016 Brent Laster
28
@BrentCLaster
Git in One Picture
Staging Area
Remote Repository
Local Repository
Working Directory
P
u
l
l
Dev
Prod
Public
Test
C
h
e
c
k
o
u
t
Server
Add
Commit
Push Clone
Local Machine
F
e
t
c
h
29
© 2016 Brent Laster
29
@BrentCLaster
Git Granularity (What is a unit?)
30
© 2016 Brent Laster
30
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
31
© 2016 Brent Laster
31
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
file1.javafile1.java
32
© 2016 Brent Laster
32
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
file1.java
CVS
file1.java
33
© 2016 Brent Laster
33
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
file1.java
CVS
file1.java
Delta
34
© 2016 Brent Laster
34
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
 In Git, the unit of granularity is usually a tree
file1.java
CVS
file1.java
Delta
35
© 2016 Brent Laster
35
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
 In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
file1.java
Delta
36
© 2016 Brent Laster
36
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
 In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
file1.java
Delta
37
© 2016 Brent Laster
37
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
 In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
GitCommit
file1.java
Delta
38
© 2016 Brent Laster
38
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
 In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
GitCommit
file1.java
Delta
39
© 2016 Brent Laster
39
@BrentCLaster
Git Granularity (What is a unit?)
 In traditional source control, the unit of granularity is
usually a file
 In Git, the unit of granularity is usually a tree
dir: proj1
file1.java
file2.java
Working directory
file1.java
CVS
Git
file1.java
Delta
Commit
Snapshot
40
© 2016 Brent Laster
40
@BrentCLaster
Merging: What is a Fast-forward?
 Assume you have three branches as below
 You want to merge hotfix into master (so master will
have your hotfix for future development)
C2
C3
C0 C1 C4
feature
hotfix
41
© 2016 Brent Laster
41
@BrentCLaster
Merging: What is a Fast-forward?
 Assume you have three branches as below
 You want to merge hotfix into master (so master will
have your hotfix for future development)
$ git checkout master
C2
C3
C0 C1 C4
feature
hotfix
42
© 2016 Brent Laster
42
@BrentCLaster
Merging: What is a Fast-forward?
 Assume you have three branches as below
 You want to merge hotfix into master (so master will
have your hotfix for future development)
$ git checkout master
$ git merge hotfix
C2
C3
C0 C1 C4
feature
hotfix
43
© 2016 Brent Laster
43
@BrentCLaster
Merging: What is a Fast-forward?
 Assume you have three branches as below
 You want to merge hotfix into master (so master will
have your hotfix for future development)
$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast Forward
README | 1-
1 files changed, 0 insertions(+) 1 deletions (-)
C2
C3
C0 C1 C4
feature
hotfix
44
© 2016 Brent Laster
44
@BrentCLaster
Merging: What is a Fast-forward?
 Assume you have three branches as below
 You want to merge hotfix into master (so master will
have your hotfix for future development)
$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast Forward
README | 1-
1 files changed, 0 insertions(+) 1 deletions (-)
About “Fast Forward” – because commit pointed to by branch merged was
directly “upstream” of the current commit, Git moves the pointer forward
C2
C3
C0 C1 C4
feature
hotfix
45
© 2016 Brent Laster
45
@BrentCLaster
Merging: What is a Fast-forward?
 Assume you have three branches as below
 You want to merge hotfix into master (so master will
have your hotfix for future development)
$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast Forward
README | 1-
1 files changed, 0 insertions(+) 1 deletions (-)
About “Fast Forward” – because commit pointed to by branch merged was
directly “upstream” of the current commit, Git moves the pointer forward
(Both branches were in the same line of development, so the net result is that
master and hotfix point to the same commit)
C2
C3
C0 C1 C4
feature
hotfix
46
© 2016 Brent Laster
46
@BrentCLaster
 Assume branching scenario below
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
47
© 2016 Brent Laster
47
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
48
© 2016 Brent Laster
48
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
49
© 2016 Brent Laster
49
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
50
© 2016 Brent Laster
50
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
51
© 2016 Brent Laster
51
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
52
© 2016 Brent Laster
52
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master
$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
53
© 2016 Brent Laster
53
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master
$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
54
© 2016 Brent Laster
54
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master
$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
55
© 2016 Brent Laster
55
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
Merging: What is a 3-way Merge?
$ git checkout master
$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
56
© 2016 Brent Laster
56
@BrentCLaster
 Assume branching scenario below
 master and feature branches have both diverged (changed) since their last
common ancestor (commit/snapshot)
 Intent is to change to master and merge in feature
 Current commit on target branch isn’t a direct ancestor of current commit on
branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)
 Git does 3-way merge using common ancestor
 Instead of just moving branch pointer forward, Git creates a new snapshot and
a new commit that points to it called a “merge commit”
Merging: What is a 3-way Merge?
$ git checkout master
$ git merge feature
C2
C3
C4
C5
feature
C0 C1
Common
Ancestor
Branch Tip
Branch Tip
master
57
© 2016 Brent Laster
57
@BrentCLaster
Merging: What is a Rebase?
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
58
© 2016 Brent Laster
58
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
59
© 2016 Brent Laster
59
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
60
© 2016 Brent Laster
60
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
61
© 2016 Brent Laster
61
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
62
© 2016 Brent Laster
62
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
63
© 2016 Brent Laster
63
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
64
© 2016 Brent Laster
64
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
65
© 2016 Brent Laster
65
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
$ git checkout feature
$ git rebase master
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1
master
66
© 2016 Brent Laster
66
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
 Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto)
$ git checkout feature
$ git rebase master
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1 C2
master
67
© 2016 Brent Laster
67
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
 Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto)
 Gets the diff introduced by each commit of the branch you are on, saving them to temporary files
$ git checkout feature
$ git rebase master
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1 C2
master
68
© 2016 Brent Laster
68
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
 Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto)
 Gets the diff introduced by each commit of the branch you are on, saving them to temporary files
 Applies each change in turn
$ git checkout feature
$ git rebase master
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1 C3’ C5’C2
master
69
© 2016 Brent Laster
69
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
 Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto)
 Gets the diff introduced by each commit of the branch you are on, saving them to temporary files
 Applies each change in turn
 Moves the branch to the new rebase point
$ git checkout feature
$ git rebase master
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1 C3’ C5’C2
master
70
© 2016 Brent Laster
70
@BrentCLaster
Merging: What is a Rebase?
 Rebase – take all of the changes that were committed on one branch and
replay them on another one.
 Concepts in simple syntax (git rebase branch2 [branch1]):
 Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)
 Current branch (or branch1 if supplied) is one having its branchpoint moved
 Branch2 (or commit) provided as first/only argument is the new branchpoint
 In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of
branch2)”
 Process:
 Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing
onto)
 Gets the diff introduced by each commit of the branch you are on, saving them to temporary files
 Applies each change in turn
 Moves the branch to the new rebase point
$ git checkout feature
$ git rebase master
C3
C4
C5
C0
Common
Ancestor
C2
feature
C1 C3’ C5’C2
master
71
© 2016 Brent Laster
71
@BrentCLaster
Command: Git Stash
 Purpose -- allow you to keep a backup copy of your work
that hasn’t been committed yet
 Use case - you want to switch branches but don’t want
to lose work that hasn’t been committed; you want to
save something you’ve tried and may want to come back
to
 Syntax:
72
© 2016 Brent Laster
72
@BrentCLaster
Stash
73
© 2016 Brent Laster
73
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
74
© 2016 Brent Laster
74
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory*
75
© 2016 Brent Laster
75
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory*
*
76
© 2016 Brent Laster
76
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory*
*
> git stash
77
© 2016 Brent Laster
77
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory*
*
> git stash
78
© 2016 Brent Laster
78
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{0}
> git stash
79
© 2016 Brent Laster
79
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
**
stash@{0}
> git stash
80
© 2016 Brent Laster
80
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
**
**
stash@{0}
> git stash
81
© 2016 Brent Laster
81
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
**
**
stash@{0}
> git stash
#
82
© 2016 Brent Laster
82
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
**
**
stash@{0}
> git stash> git stash -u
#
83
© 2016 Brent Laster
83
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
stash@{0}
stash@{0}
stash@{1}
> git stash -u
84
© 2016 Brent Laster
84
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
***
stash@{0}
stash@{0}
stash@{1}
> git stash -u
85
© 2016 Brent Laster
85
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
***
***
stash@{0}
stash@{0}
stash@{1}
> git stash -u
86
© 2016 Brent Laster
86
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
***
***
stash@{0}
stash@{0}
stash@{1}
> git stash save “cool feature”
87
© 2016 Brent Laster
87
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
stash@{0}
Staging
Area ***
stash@{2}
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working
Directory
***
88
© 2016 Brent Laster
88
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
stash@{0}
Staging
Area ***
stash@{2}
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working
Directory
***
> git stash apply stash@{1}
89
© 2016 Brent Laster
89
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
stash@{0}
Staging
Area ***
stash@{2}
**
**
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working
Directory
*** #
> git stash apply stash@{1}
90
© 2016 Brent Laster
90
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
stash@{0}
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
stash@{0}
Staging
Area ***
stash@{2}
**
**
stash@{1}
stash@{0}
stash@{0}stash@{1}
stash@{1}stash@{2}
“cool feature”
Working
Directory
*** #
$ git stash pop stash@{2}
91
© 2016 Brent Laster
91
@BrentCLaster
Stash
Staging Area
Staging Area
Local Repository
Working Directory
Staging
Area *
Working
Directory *
stash@{1}
Staging
Area **
Working
Directory
**#
stash@{0}
Staging
Area ***
***
***
stash@{0}stash@{1}
“cool feature”
Working
Directory
*** #
$ git stash pop stash@{2}
92
© 2016 Brent Laster
92
@BrentCLaster
Command: Git Reset
 Purpose -- allow you to “roll back” so that your branch
points at a previous commit ; optionally also update
staging area and working directory to that commit
 Use case - you want to update your local environment
back to a previous point in time; you want to overwrite or
a local change you’ve made
 Syntax:
 Warning: --hard overwrites everything
93
© 2016 Brent Laster
93
@BrentCLaster
Command: Git Revert
 Purpose -- allow you to “undo” by adding a new change
that cancels out effects of previous one
 Use case - you want to cancel out a previous change but
not roll things back
 Syntax:
 Note: The net result of using this command vs. reset can
be the same. If so, and content that is being
reset/revert has been pushed such that others may be
consuming it, preference is for revert.
94
© 2016 Brent Laster
94
@BrentCLaster
Local Repository
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
Line 1
Line 2
Line 1Line 1 Line 1
Line 2
tag: current
95
© 2016 Brent Laster
95
@BrentCLaster
Local Repository
git reset --hard 87ba8bc
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
Line 1
Line 2
Line 1
Line 1 Line 1
Line 2
tag: current
96
© 2016 Brent Laster
96
@BrentCLaster
Local Repository
git reset --hard 87ba8bc
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
Line 1
Line 2
Line 1
Line 1 Line 1
Line 2
tag: current
97
© 2016 Brent Laster
97
@BrentCLaster
Local Repository
git reset current~1 [--mixed]
Reset and Revert
Line 1
Staging Area
Working Directory
XYZ
ABC
Line 1
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
Line 1
Line 2
Line 1
Line 1 Line 1
Line 2
tag: current
98
© 2016 Brent Laster
98
@BrentCLaster
Local Repository
git reset current~1 [--mixed]
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
Line 1 Line 1
Line 2
tag: current
99
© 2016 Brent Laster
99
@BrentCLaster
Local Repository
git revert HEAD~1
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
Line 1
Line 2
Line 1 Line 1
Line 2
tag: current
100
© 2016 Brent Laster
100
@BrentCLaster
Local Repository
git revert HEAD~1
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
c1c8bd4
Line 1
Line 2
Line 1 Line 1
Line 2
tag: current
101
© 2016 Brent Laster
101
@BrentCLaster
Local Repository
Reset and Revert
Line 1
Staging Area
Working Directory
87ba8bc 43bd3ef d21be2c
Line 1
Line 2
Line 3
c1c8bd4
Line 1
Line 2
Line 1 Line 1
Line 2
tag: current
102
© 2016 Brent Laster
102
@BrentCLaster
Command: Git Rerere (Reuse Recorded
Resolution)
 Purpose -- allows recording of how you solve a merge
situation and then can automatically resolve the same
situation in the same way if needed later
 Use case - trial and repeated merges; merging newer
versions of a branch with the same conflicts into a newer
one periodically; resolve conflicts after reset or revert;
applicable to any repeated merge case: rebase, merge
 Syntax:
 Note: This is a “state” command. Enabled by turning on
a state in Git, rather than just running a command
 Enabled via git config --global rerere.enabled 1
» Then runs automatically
 Invoked directly via git rerere for related commands or options
103
© 2016 Brent Laster
103
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
Git Rerere 1
104
© 2016 Brent Laster
104
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
Git Rerere 1
105
© 2016 Brent Laster
105
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
rr-cache
Git Rerere 1
106
© 2016 Brent Laster
106
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
rr-cache
Git Rerere 1
107
© 2016 Brent Laster
107
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File A File CFile A File C
rr-cache
Git Rerere 1
108
© 2016 Brent Laster
108
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File A File CFile A File C
rr-cache
File A File C
Git Rerere 1
109
© 2016 Brent Laster
109
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File A File CFile A File C
rr-cache
File A File C
File B
<<>>
preimage
Git Rerere 1
110
© 2016 Brent Laster
110
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File A File CFile A File C
rr-cache
File A File C
File B
<<>>
preimage
Git Rerere 1
111
© 2016 Brent Laster
111
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File A File CFile A File C
rr-cache
File A File C
File B
<<>>
preimage
Git Rerere 1
112
© 2016 Brent Laster
112
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File BFile A File CFile A File C
rr-cache
File A File C
File B
<<>>
preimage
Git Rerere 1
113
© 2016 Brent Laster
113
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
File A File CFile BFile A File C
rr-cache
File A File C
File B
<<>>
preimage
Git Rerere 1
114
© 2016 Brent Laster
114
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B
<<>>
preimage
Git Rerere 1
115
© 2016 Brent Laster
115
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B
<<>>
preimage postimage
Git Rerere 1
116
© 2016 Brent Laster
116
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B
<<>>
preimage postimage
File B
Git Rerere 1
117
© 2016 Brent Laster
117
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B
<<>>
preimage postimage
File B
Git Rerere 1
118
© 2016 Brent Laster
118
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B
<<>>
preimage postimage
File B
Git Rerere 1
119
© 2016 Brent Laster
119
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
rr-cache
File B
<<>>
preimage postimage
File B
Git Rerere 2
120
© 2016 Brent Laster
120
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File BFile B
File A File C
rr-cache
File B
<<>>
preimage postimage
File B
Git Rerere 2
121
© 2016 Brent Laster
121
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File B
<<>>
File A File CFile A File C
rr-cache
File A File C
File B
<<>>
preimage postimage
File B
Git Rerere 2
122
© 2016 Brent Laster
122
© 2016 Brent Laster@BrentCLaster
Local Repository
feature
Staging Area
File B
Working Directory
File C
File A
File B
master
File A
File C
File B
File A
File C
File A File C
File B
File A File C
rr-cache
File A File C
File B
<<>>
preimage postimage
File B
Git Rerere 2
123
© 2016 Brent Laster
123
@BrentCLaster
Command: Bisect
 Purpose - Use “automated” binary search through Git’s history to find a
specific commit that first introduced a problem (i.e. “first bad commit”)
 Use case - Quickly locate the commit in Git’s history that introduced a
bug
 Syntax:
124
© 2016 Brent Laster
124
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
125
© 2016 Brent Laster
125
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest versionVersion 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
126
© 2016 Brent Laster
126
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest versionVersion 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
127
© 2016 Brent Laster
127
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest version
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
128
© 2016 Brent Laster
128
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest version
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
129
© 2016 Brent Laster
129
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest version
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
130
© 2016 Brent Laster
130
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest version
 try code
 git bisect start
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
131
© 2016 Brent Laster
131
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
132
© 2016 Brent Laster
132
@BrentCLaster
LOCAL REPOSITORY
Version 1Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
133
© 2016 Brent Laster
133
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
134
© 2016 Brent Laster
134
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
135
© 2016 Brent Laster
135
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
136
© 2016 Brent Laster
136
@BrentCLaster
LOCAL REPOSITORY
Version 1
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
137
© 2016 Brent Laster
137
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
138
© 2016 Brent Laster
138
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
139
© 2016 Brent Laster
139
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
140
© 2016 Brent Laster
140
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 5
Version 2
Version 7
Version 6
WORKING DIRECTORY
141
© 2016 Brent Laster
141
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
142
© 2016 Brent Laster
142
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
143
© 2016 Brent Laster
143
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
144
© 2016 Brent Laster
144
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 7
Version 6
WORKING DIRECTORY
145
© 2016 Brent Laster
145
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
 git bisect bad (bisect checks out version 6)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
146
© 2016 Brent Laster
146
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
 git bisect bad (bisect checks out version 6)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
147
© 2016 Brent Laster
147
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
 git bisect bad (bisect checks out version 6)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
148
© 2016 Brent Laster
148
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
 git bisect bad (bisect checks out version 6)
 try code
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
149
© 2016 Brent Laster
149
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
 git bisect bad (bisect checks out version 6)
 try code
 git bisect bad (git reports version 6 as the first
bad commit)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
WORKING DIRECTORY
150
© 2016 Brent Laster
150
@BrentCLaster
LOCAL REPOSITORY
Version 1
Bisect
 checkout latest version
 try code
 git bisect start
 git bisect bad
 checkout earlier version ( user checks out)
 try code
 git bisect good (bisect checks out version 5)
 try code
 git bisect good (bisect checks out version 7)
 try code
 git bisect bad (bisect checks out version 6)
 try code
 git bisect bad (git reports version 6 as the first
bad commit)
Version 3
Version 4
Version 5
Version 6
Version 7
Version 8
Version 9
Version 10
Version 2
Version 6
FIRST BAD COMMIT
WORKING DIRECTORY
151
© 2016 Brent Laster
151
@BrentCLaster
Background: Switching between Branches
Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
152
© 2016 Brent Laster
152
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
153
© 2016 Brent Laster
153
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
154
© 2016 Brent Laster
154
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
155
© 2016 Brent Laster
155
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
156
© 2016 Brent Laster
156
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
 Reverts files in working directory to
snapshot pointed to by <branch> Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
157
© 2016 Brent Laster
157
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
 Reverts files in working directory to
snapshot pointed to by <branch>
 Updates indicators
Local Repository
Working Directory
87ba8bc 43bd3ef d21be2c c1c8bd4
158
© 2016 Brent Laster
158
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
 Reverts files in working directory to
snapshot pointed to by <branch>
 Updates indicators
 git branch
Local Repository
Working Directory
*
87ba8bc 43bd3ef d21be2c c1c8bd4
master
testing
159
© 2016 Brent Laster
159
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
 Reverts files in working directory to
snapshot pointed to by <branch>
 Updates indicators
git checkout testing
 git branch
Local Repository
Working Directory
*
87ba8bc 43bd3ef d21be2c c1c8bd4
master
testing
160
© 2016 Brent Laster
160
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
 Reverts files in working directory to
snapshot pointed to by <branch>
 Updates indicators
git checkout testing
git checkout master
 git branch
Local Repository
Working Directory
*
87ba8bc 43bd3ef d21be2c c1c8bd4
master
testing
161
© 2016 Brent Laster
161
@BrentCLaster
Background: Switching between Branches
Command: git checkout <branch>
git checkout master
 Does three things
 Moves HEAD pointer back to <branch>
 Reverts files in working directory to
snapshot pointed to by <branch>
 Updates indicators
git checkout testing
git checkout master
git checkout testing
 git branch
Local Repository
Working Directory
*
87ba8bc 43bd3ef d21be2c c1c8bd4
master
testing
162
© 2016 Brent Laster
162
@BrentCLaster
Command: Worktrees
 Purpose - Allows multiple, separate Working Areas attached
to one Local Repository
 Use case - Simultaneous development in multiple branche
 Syntax
 git worktree add [-f] [--detach] [-b <new-branch>] <path> [<branch>]
 git worktree list [--porcelain]
 git worktree prune [-n] [-v] [--expire <expire>]
 Notes
 “Traditional” working directory is called the main working tree; Any new
trees you create with this command are called linked working trees
 Information about working trees is stored in the .git area (assuming .git
default GIT_DIR is used)
 Working tree information is stored in .git/worktrees/<name of
worktree>.
163
© 2016 Brent Laster
163
@BrentCLaster
Worktrees
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
164
© 2016 Brent Laster
164
@BrentCLaster
Worktrees
 git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
165
© 2016 Brent Laster
165
@BrentCLaster
Worktrees
 git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
worktrees/
tree1
166
© 2016 Brent Laster
166
@BrentCLaster
Worktrees
 git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
worktrees/
tree1
167
© 2016 Brent Laster
167
@BrentCLaster
Worktrees
 git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
worktrees/
tree1
gitdir
HEAD
etc.
168
© 2016 Brent Laster
168
@BrentCLaster
Worktrees
 git worktree add -b exp tree1
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
worktrees/
tree1
gitdir
HEAD
etc.
tree1
Linked Working Tree
Staging Area
Working Directory
(exp)
169
© 2016 Brent Laster
169
@BrentCLaster
Worktrees
 git worktree add -b exp tree1
 git worktree add -b prod tree2
Remote Repository
Main Working Tree
Server
Add
Commit
Push Pull
Staging Area
Local Repository
Working Directory
(master)
Local Machine
worktrees/
tree1
gitdir
HEAD
etc.
tree1
Linked Working Tree
Staging Area
Working Directory
(exp)
gitdir
HEAD
etc.
tree2
Linked Working Tree
Staging Area
Working Directory
(prod)
tree2
170
© 2016 Brent Laster
170
@BrentCLaster
Command: Submodules
 Purpose - Allows including a separate repository with your current repository
 Use case - include the Git repository for one or more dependencies along with the
original repository for a project
 Syntax
git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>]
[--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…​]
git submodule [--quiet] init [--] [<path>…​]
git submodule [--quiet] deinit [-f|--force] [--] <path>…​
git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch]
[-f|--force] [--rebase|--merge] [--reference <repository>]
[--depth <depth>] [--recursive] [--] [<path>…​]
git submodule [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
[commit] [--] [<path>…​]
git submodule [--quiet] foreach [--recursive] <command>
git submodule [--quiet] sync [--recursive] [--] [<path>…​]
 Notes
 Creates a subdirectory off of your original repository that contains a clone of another Git
repository
 Original repository is typically called superproject
 Metadata stored in .gitmodules file
171
© 2016 Brent Laster
171
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Submodules 1
172
© 2016 Brent Laster
172
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
What happens when you add a
submodule?
Submodules 1
173
© 2016 Brent Laster
173
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
What happens when you add a
submodule?
Submodules 1
174
© 2016 Brent Laster
174
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
Submodules 1
175
© 2016 Brent Laster
175
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
Submodules 1
176
© 2016 Brent Laster
176
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
Submodules 1
177
© 2016 Brent Laster
177
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
Submodules 1
178
© 2016 Brent Laster
178
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
Submodules 1
179
© 2016 Brent Laster
179
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
.gitmodules
Submodules 1
180
© 2016 Brent Laster
180
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
.gitmodules
Submodules 1
181
© 2016 Brent Laster
181
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
.gitmodules
Submodules 1
182
© 2016 Brent Laster
182
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
.gitmodules
Submodules 1
183
© 2016 Brent Laster
183
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
.gitmodules
Submodules 1
184
© 2016 Brent Laster
184
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
.gitmodules
mod1
<current
commit>
Submodules 1
185
© 2016 Brent Laster
185
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
.gitmodules
mod1
<current
commit>
Submodules 1
186
© 2016 Brent Laster
186
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
.gitmodules
mod1
<current
commit>
Submodules 1
187
© 2016 Brent Laster
187
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
7. Commit
modules/
mod1
gitdir
HEAD
etc.
Submodules 1
188
© 2016 Brent Laster
188
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
7. Commit
modules/
mod1
gitdir
HEAD
etc.
submodule
reference
Submodules 1
189
© 2016 Brent Laster
189
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
7. Commit
modules/
mod1
gitdir
HEAD
etc.
submodule
reference
commit pointed
to by
submodule
reference
Submodules 1
190
© 2016 Brent Laster
190
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
7. Commit
modules/
mod1
gitdir
HEAD
etc.
submodule
reference
commit pointed
to by
submodule
reference
Head of
branch
Submodules 1
191
© 2016 Brent Laster
191
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
7. Commit
modules/
mod1
gitdir
HEAD
etc.
submodule
reference
commit pointed
to by
submodule
reference
Head of
branch
8. Push
Submodules 1
192
© 2016 Brent Laster
192
@BrentCLaster
Remote Repository
proj_dir
superproject
Staging Area
Local Repository
Working Directory
Remote Repository
proj_dir/mod1
submodule 1
Staging Area
Working Directory
Local Repository
What happens when you add a
submodule?
1. Git clones down the repository for
the submodule into the current
directory.
2. By default, Git checks out the
master branch.
3. Git adds the submodule’s path for
cloning to the .gitmodules file.
4. Git adds the .gitmodules file to
the index, ready to be committed.
5. Git adds the current commit
ID of the submodule to the
index, ready to be committed.
6. To complete the add process, you need
to complete the Git workflow for the
staged changes. From the superproject’s
directory:
7. Commit
modules/
mod1
gitdir
HEAD
etc.
submodule
reference
commit pointed
to by
submodule
reference
Head of
branch
8. Push
Submodules 1
193
© 2016 Brent Laster
193
@BrentCLaster
Remote Repository
How do we clone a repository with
submodules?
Submodules 2
194
© 2016 Brent Laster
194
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/
mod1
gitdir
HEAD
etc.
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
Submodules 2
195
© 2016 Brent Laster
195
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/
mod1
gitdir
HEAD
etc.
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
2. git submodule init - puts submodule
location information in
superproject’s config file
Remote Repository
Submodules 2
196
© 2016 Brent Laster
196
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/
mod1
gitdir
HEAD
etc.
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
2. git submodule init - puts submodule
location information in
superproject’s config file
Remote Repository
Submodules 2
197
© 2016 Brent Laster
197
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
modules/
mod1
gitdir
HEAD
etc.
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
2. git submodule init - puts submodule
location information in
superproject’s config file
Remote Repository
3. git submodule update - actually
clones repositories for submodules
into the corresponding
subdirectories and checks out the
indicated commits for the
containing project
Submodules 2
198
© 2016 Brent Laster
198
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
2. git submodule init - puts submodule
location information in
superproject’s config file
Remote Repository
3. git submodule update - actually
clones repositories for submodules
into the corresponding
subdirectories and checks out the
indicated commits for the
containing project
Submodules 2
199
© 2016 Brent Laster
199
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
2. git submodule init - puts submodule
location information in
superproject’s config file
Remote Repository
3. git submodule update - actually
clones repositories for submodules
into the corresponding
subdirectories and checks out the
indicated commits for the
containing project
submodule
reference
Submodules 2
200
© 2016 Brent Laster
200
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
How do we clone a repository with
submodules?
1. git clone - puts in structure - but
submodules areas are empty
2. git submodule init - puts submodule
location information in
superproject’s config file
Remote Repository
3. git submodule update - actually
clones repositories for submodules
into the corresponding
subdirectories and checks out the
indicated commits for the
containing project
Note: Shortcuts -
git submodule update --init and
git clone --recursive or
--recurse-submodules
submodule
reference
Submodules 2
201
© 2016 Brent Laster
201
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
Incorporating updates to submodules:
Submodules 3
202
© 2016 Brent Laster
202
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
Submodules 3
203
© 2016 Brent Laster
203
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
Submodules 3
204
© 2016 Brent Laster
204
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
Submodules 3
205
© 2016 Brent Laster
205
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
Submodules 3
206
© 2016 Brent Laster
206
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
Submodules 3
207
© 2016 Brent Laster
207
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
Submodules 3
208
© 2016 Brent Laster
208
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
Submodules 3
209
© 2016 Brent Laster
209
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
Submodules 3
210
© 2016 Brent Laster
210
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
Submodules 3
211
© 2016 Brent Laster
211
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
212
© 2016 Brent Laster
212
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
213
© 2016 Brent Laster
213
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
214
© 2016 Brent Laster
214
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
215
© 2016 Brent Laster
215
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
216
© 2016 Brent Laster
216
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
.gitmodules
mod1
<current
commit>
Submodules 3
3. To update: add, commit, and push
reference changes.
217
© 2016 Brent Laster
217
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
218
© 2016 Brent Laster
218
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
219
© 2016 Brent Laster
219
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
220
© 2016 Brent Laster
220
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
221
© 2016 Brent Laster
221
@BrentCLaster
Remote Repository
main
superproject
Staging Area
Local Repository
Working Directory
main/mod1
submodule 1
Staging Area
Working Directory
Local Repository
modules/
mod1
gitdir
HEAD
etc.
commit pointed
to by
submodule
reference
Head of
branch
Remote Repository
submodule
reference
new commitIncorporating updates to submodules:
1. You can
$ cd mod1; git checkout <branch> ; git
pull
OR
$ git pull --recurse-submodules; cd
<module dir>; git merge origin/master
OR
$ git submodule update --remote
2. Although module has been updated,
references that the superproject has to it
haven’t been updated
Submodules 3
3. To update: add, commit, and push
reference changes.
222
© 2016 Brent Laster
222
@BrentCLaster
Submodule - Challenges
 Challenges around using submodules nearly always
involve keeping submodule content (and “current”
commit) in sync with submodule references in
superproject
 If references are wrong, operations like “git submodule
update” will backlevel submodule content to commits in
reference
 If these references are out of sync and that
inconsistency is pushed to the remote for the
superproject, then other users that pull that version of
the superproject can end up back-leveling their
submodules, even if they’ve updated their superproject
before.
223
© 2016 Brent Laster
223
@BrentCLaster
Command: Subtrees
 Purpose - Allows including a copy of a separate
repository with your current repository
 Use case - include a copy of a Git repository for one or
more dependencies along with the original repository for
a project
 Syntax
 Notes
 No links like a submodule - just a copy in a subdirectory
 Advantage - no links to maintain
 Disadvantage - extra content to carry around with your project
git subtree add -P <prefix> <commit>
git subtree add -P <prefix> <repository> <ref>
git subtree pull -P <prefix> <repository> <ref>
git subtree push -P <prefix> <repository> <ref>
git subtree merge -P <prefix> <commit>
git subtree split -P <prefix> [OPTIONS] [<commit>]
224
© 2017 Brent Laster
22
4
Subtrees
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
225
© 2017 Brent Laster
22
5
Subtrees
 Adding a copy from a remote as
a subtree Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
226
© 2017 Brent Laster
22
6
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
227
© 2017 Brent Laster
22
7
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master

Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
228
© 2017 Brent Laster
22
8
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master

Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
229
© 2017 Brent Laster
22
9
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
230
© 2017 Brent Laster
23
0
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
231
© 2017 Brent Laster
23
1
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
 branch (master) is optional
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
232
© 2017 Brent Laster
23
2
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
 branch (master) is optional
 directory listing of myproject now
shows subproj as subdirectory
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
233
© 2017 Brent Laster
23
3
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
 branch (master) is optional
 directory listing of myproject now
shows subproj as subdirectory
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
234
© 2017 Brent Laster
23
4
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
 branch (master) is optional
 directory listing of myproject now
shows subproj as subdirectory
 Looking in the logs of the
subproject will show the
squashed history
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
235
© 2017 Brent Laster
23
5
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
 branch (master) is optional
 directory listing of myproject now
shows subproj as subdirectory
 Looking in the logs of the
subproject will show the
squashed history
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
236
© 2017 Brent Laster
23
6
Subtrees
 Adding a copy from a remote as
a subtree
 cd myproject
 git subtree add --prefix
subproject --squash subproj.git
master
 Use “prefix” option to specify path for
subproject
 Use “squash” option to compress
history from remote before adding it
 branch (master) is optional
 directory listing of myproject now
shows subproj as subdirectory
 Looking in the logs of the
subproject will show the
squashed history
 To get the latest, use pull
Remote Repository
myproject
superproject
superproject
Staging Area
(myproject)
Local Repository
Working Directory
Remote Repository
(subproj)
myproject/subproject
subtree
Staging Area
Working Directory
Local Repository
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features
Advanced Git: Functionality and Features

Mais conteúdo relacionado

Mais procurados

Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / GithubPaige Bailey
 
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...Edureka!
 
Git 101 tutorial presentation
Git 101 tutorial presentationGit 101 tutorial presentation
Git 101 tutorial presentationTerry Wang
 
Git and github fundamental
Git and github fundamentalGit and github fundamental
Git and github fundamentalRajesh Kumar
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperJohn Stevenson
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Writing Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfWriting Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfAll Things Open
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015mwrather
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
 
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...OpenCity Community
 

Mais procurados (20)

Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / Github
 
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git 101 tutorial presentation
Git 101 tutorial presentationGit 101 tutorial presentation
Git 101 tutorial presentation
 
Git and github fundamental
Git and github fundamentalGit and github fundamental
Git and github fundamental
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Inside GitHub with Chris Wanstrath
Inside GitHub with Chris WanstrathInside GitHub with Chris Wanstrath
Inside GitHub with Chris Wanstrath
 
Migrating To GitHub
Migrating To GitHub  Migrating To GitHub
Migrating To GitHub
 
Writing Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future SelfWriting Commits for You, Your Friends, and Your Future Self
Writing Commits for You, Your Friends, and Your Future Self
 
Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015Introduction to Git, DrupalCamp LA 2015
Introduction to Git, DrupalCamp LA 2015
 
Git training
Git trainingGit training
Git training
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
 

Destaque

Getting Git Right
Getting Git RightGetting Git Right
Getting Git RightSven Peters
 
DC API Meetup 6/18/2014: FBOpen
DC API Meetup 6/18/2014: FBOpenDC API Meetup 6/18/2014: FBOpen
DC API Meetup 6/18/2014: FBOpenAlison Rowland
 
The Greatest git Flag of All
The Greatest git Flag of AllThe Greatest git Flag of All
The Greatest git Flag of AllAlison Rowland
 
Open refine reconciliation service api (dc python 2013_03_05)
Open refine reconciliation service api (dc python 2013_03_05)Open refine reconciliation service api (dc python 2013_03_05)
Open refine reconciliation service api (dc python 2013_03_05)Alison Rowland
 
Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositoriesJulien Pivotto
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAdvanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAtlassian
 
Becoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola PaolucciBecoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola PaolucciAtlassian
 

Destaque (11)

Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
DC API Meetup 6/18/2014: FBOpen
DC API Meetup 6/18/2014: FBOpenDC API Meetup 6/18/2014: FBOpen
DC API Meetup 6/18/2014: FBOpen
 
The Greatest git Flag of All
The Greatest git Flag of AllThe Greatest git Flag of All
The Greatest git Flag of All
 
Open refine reconciliation service api (dc python 2013_03_05)
Open refine reconciliation service api (dc python 2013_03_05)Open refine reconciliation service api (dc python 2013_03_05)
Open refine reconciliation service api (dc python 2013_03_05)
 
Getting Into Git
Getting Into GitGetting Into Git
Getting Into Git
 
Git Submodules
Git SubmodulesGit Submodules
Git Submodules
 
Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositories
 
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun StuffAdvanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
Advanced Git Techniques: Subtrees, Grafting, and Other Fun Stuff
 
Becoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola PaolucciBecoming a Git Master - Nicola Paolucci
Becoming a Git Master - Nicola Paolucci
 
Git submodule
Git submoduleGit submodule
Git submodule
 
Recycling
RecyclingRecycling
Recycling
 

Semelhante a Advanced Git: Functionality and Features

That's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICThat's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICLa FeWeb
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Simplilearn
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
 
Be a Happier Developer with Git / Productive Team #gettinggitright
Be a Happier Developer with Git / Productive Team #gettinggitright Be a Happier Developer with Git / Productive Team #gettinggitright
Be a Happier Developer with Git / Productive Team #gettinggitright Shunsuke (Sean) Osawa
 
Git essential training & sharing self
Git essential training & sharing selfGit essential training & sharing self
Git essential training & sharing selfChen-Tien Tsai
 
Git interview questions | Edureka
Git interview questions | EdurekaGit interview questions | Edureka
Git interview questions | EdurekaEdureka!
 
Hardening Your CI/CD Pipelines with GitOps and Continuous Security
Hardening Your CI/CD Pipelines with GitOps and Continuous SecurityHardening Your CI/CD Pipelines with GitOps and Continuous Security
Hardening Your CI/CD Pipelines with GitOps and Continuous SecurityWeaveworks
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting StartedWildan Maulana
 
Presentation on Repository Control System
Presentation on Repository Control SystemPresentation on Repository Control System
Presentation on Repository Control SystemMd. Mujahid Islam
 
Introduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemIntroduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemAlbanLevy
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenchesNuno Caneco
 
Git_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_GuidewireGit_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_GuidewireGandhi Ramu
 
Version control with git
Version control with gitVersion control with git
Version control with gitPurav Gandhi
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developersDmitry Guyvoronsky
 

Semelhante a Advanced Git: Functionality and Features (20)

That's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETICThat's (g)it! par Sébastien Dawans CETIC
That's (g)it! par Sébastien Dawans CETIC
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
Be a Happier Developer with Git / Productive Team #gettinggitright
Be a Happier Developer with Git / Productive Team #gettinggitright Be a Happier Developer with Git / Productive Team #gettinggitright
Be a Happier Developer with Git / Productive Team #gettinggitright
 
Git essential training & sharing self
Git essential training & sharing selfGit essential training & sharing self
Git essential training & sharing self
 
Git interview questions | Edureka
Git interview questions | EdurekaGit interview questions | Edureka
Git interview questions | Edureka
 
Webinar : SVN to GIT Migration
Webinar : SVN to GIT Migration Webinar : SVN to GIT Migration
Webinar : SVN to GIT Migration
 
Hardening Your CI/CD Pipelines with GitOps and Continuous Security
Hardening Your CI/CD Pipelines with GitOps and Continuous SecurityHardening Your CI/CD Pipelines with GitOps and Continuous Security
Hardening Your CI/CD Pipelines with GitOps and Continuous Security
 
Git Workshop : Getting Started
Git Workshop : Getting StartedGit Workshop : Getting Started
Git Workshop : Getting Started
 
Presentation on Repository Control System
Presentation on Repository Control SystemPresentation on Repository Control System
Presentation on Repository Control System
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
 
Introduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemIntroduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control system
 
Git from the trenches
Git from the trenchesGit from the trenches
Git from the trenches
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
 
Git_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_GuidewireGit_and_GitHub Integration_with_Guidewire
Git_and_GitHub Integration_with_Guidewire
 
Git 1
Git 1Git 1
Git 1
 
Version control with git
Version control with gitVersion control with git
Version control with git
 
3 Git
3 Git3 Git
3 Git
 
Git 101
Git 101Git 101
Git 101
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developers
 

Último

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Último (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Advanced Git: Functionality and Features

  • 1. 1 © 2016 Brent Laster 1 © 2016 Brent Laster@BrentCLaster Advanced Git: Functionality and Features Open Source 101 Conference February 4, 2017 Brent Laster (author of Professional Git)
  • 2. 2 © 2016 Brent Laster 2 @BrentCLaster About me  Senior Manager, R&D at SAS in Cary, NC  Global Trainer and Speaker  Git, Gerrit, Gradle, Jenkins, Pipelines  Author - NFJS magazine, Professional Git book  LinkedIn https://www.linkedin.com/in/brentlaster  Twitter @BrentCLaster
  • 3. 3 © 2016 Brent Laster 3 @BrentCLaster Professional Git  Available on:  Amazon.com  Wiley.com
  • 4. 4 © 2016 Brent Laster 4 @BrentCLaster Agenda  Core concepts refresh  Merging and Rebasing  Stash  Reset and Revert  Rerere  Bisect  Worktrees  Submodules  Subtrees  Interactive Rebase  Notes  Grep
  • 5. 5 © 2016 Brent Laster Check Out Commit C h e k o u t C h e c k o u t C o m m i t Clone Remote Repository Local Environment Central Server Local Machine Centralized Version Control Model Distributed Version Control Model Centralized vs. Distributed VCS
  • 6. 6 © 2016 Brent Laster 6 @BrentCLaster Git in One Picture Dev Prod Public Test
  • 7. 7 © 2016 Brent Laster 7 @BrentCLaster Git in One Picture Working DirectoryDev Prod Public Test
  • 8. 8 © 2016 Brent Laster 8 @BrentCLaster Git in One Picture Staging Area Working DirectoryDev Prod Public Test
  • 9. 9 © 2016 Brent Laster 9 @BrentCLaster Git in One Picture Staging Area Local Repository Working DirectoryDev Prod Public Test
  • 10. 10 © 2016 Brent Laster 10 @BrentCLaster Git in One Picture Staging Area Local Repository Working DirectoryDev Prod Public Test
  • 11. 11 © 2016 Brent Laster 11 @BrentCLaster Git in One Picture Staging Area Local Repository Working DirectoryDev Prod Public Test Local Machine
  • 12. 12 © 2016 Brent Laster 12 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Local Machine
  • 13. 13 © 2016 Brent Laster 13 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Local Machine
  • 14. 14 © 2016 Brent Laster 14 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Server Local Machine
  • 15. 15 © 2016 Brent Laster 15 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Server Local Machine
  • 16. 16 © 2016 Brent Laster 16 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Server Add Local Machine
  • 17. 17 © 2016 Brent Laster 17 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Server Add Local Machine
  • 18. 18 © 2016 Brent Laster 18 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Server Add Commit Local Machine
  • 19. 19 © 2016 Brent Laster 19 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test Server Add Commit Local Machine
  • 20. 20 © 2016 Brent Laster 20 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Local Machine
  • 21. 21 © 2016 Brent Laster 21 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Local Machine
  • 22. 22 © 2016 Brent Laster 22 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Push Local Machine
  • 23. 23 © 2016 Brent Laster 23 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Push Local Machine
  • 24. 24 © 2016 Brent Laster 24 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Push Clone Local Machine
  • 25. 25 © 2016 Brent Laster 25 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Push Clone Local Machine
  • 26. 26 © 2016 Brent Laster 26 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Push Clone Local Machine F e t c h
  • 27. 27 © 2016 Brent Laster 27 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working DirectoryDev Prod Public Test C h e c k o u t Server Add Commit Push Clone Local Machine F e t c h
  • 28. 28 © 2016 Brent Laster 28 @BrentCLaster Git in One Picture Staging Area Remote Repository Local Repository Working Directory P u l l Dev Prod Public Test C h e c k o u t Server Add Commit Push Clone Local Machine F e t c h
  • 29. 29 © 2016 Brent Laster 29 @BrentCLaster Git Granularity (What is a unit?)
  • 30. 30 © 2016 Brent Laster 30 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file
  • 31. 31 © 2016 Brent Laster 31 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file file1.javafile1.java
  • 32. 32 © 2016 Brent Laster 32 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file file1.java CVS file1.java
  • 33. 33 © 2016 Brent Laster 33 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file file1.java CVS file1.java Delta
  • 34. 34 © 2016 Brent Laster 34 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file  In Git, the unit of granularity is usually a tree file1.java CVS file1.java Delta
  • 35. 35 © 2016 Brent Laster 35 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file  In Git, the unit of granularity is usually a tree dir: proj1 file1.java file2.java Working directory file1.java CVS file1.java Delta
  • 36. 36 © 2016 Brent Laster 36 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file  In Git, the unit of granularity is usually a tree dir: proj1 file1.java file2.java Working directory file1.java CVS file1.java Delta
  • 37. 37 © 2016 Brent Laster 37 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file  In Git, the unit of granularity is usually a tree dir: proj1 file1.java file2.java Working directory file1.java CVS GitCommit file1.java Delta
  • 38. 38 © 2016 Brent Laster 38 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file  In Git, the unit of granularity is usually a tree dir: proj1 file1.java file2.java Working directory file1.java CVS GitCommit file1.java Delta
  • 39. 39 © 2016 Brent Laster 39 @BrentCLaster Git Granularity (What is a unit?)  In traditional source control, the unit of granularity is usually a file  In Git, the unit of granularity is usually a tree dir: proj1 file1.java file2.java Working directory file1.java CVS Git file1.java Delta Commit Snapshot
  • 40. 40 © 2016 Brent Laster 40 @BrentCLaster Merging: What is a Fast-forward?  Assume you have three branches as below  You want to merge hotfix into master (so master will have your hotfix for future development) C2 C3 C0 C1 C4 feature hotfix
  • 41. 41 © 2016 Brent Laster 41 @BrentCLaster Merging: What is a Fast-forward?  Assume you have three branches as below  You want to merge hotfix into master (so master will have your hotfix for future development) $ git checkout master C2 C3 C0 C1 C4 feature hotfix
  • 42. 42 © 2016 Brent Laster 42 @BrentCLaster Merging: What is a Fast-forward?  Assume you have three branches as below  You want to merge hotfix into master (so master will have your hotfix for future development) $ git checkout master $ git merge hotfix C2 C3 C0 C1 C4 feature hotfix
  • 43. 43 © 2016 Brent Laster 43 @BrentCLaster Merging: What is a Fast-forward?  Assume you have three branches as below  You want to merge hotfix into master (so master will have your hotfix for future development) $ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast Forward README | 1- 1 files changed, 0 insertions(+) 1 deletions (-) C2 C3 C0 C1 C4 feature hotfix
  • 44. 44 © 2016 Brent Laster 44 @BrentCLaster Merging: What is a Fast-forward?  Assume you have three branches as below  You want to merge hotfix into master (so master will have your hotfix for future development) $ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast Forward README | 1- 1 files changed, 0 insertions(+) 1 deletions (-) About “Fast Forward” – because commit pointed to by branch merged was directly “upstream” of the current commit, Git moves the pointer forward C2 C3 C0 C1 C4 feature hotfix
  • 45. 45 © 2016 Brent Laster 45 @BrentCLaster Merging: What is a Fast-forward?  Assume you have three branches as below  You want to merge hotfix into master (so master will have your hotfix for future development) $ git checkout master $ git merge hotfix Updating f42c576..3a0874c Fast Forward README | 1- 1 files changed, 0 insertions(+) 1 deletions (-) About “Fast Forward” – because commit pointed to by branch merged was directly “upstream” of the current commit, Git moves the pointer forward (Both branches were in the same line of development, so the net result is that master and hotfix point to the same commit) C2 C3 C0 C1 C4 feature hotfix
  • 46. 46 © 2016 Brent Laster 46 @BrentCLaster  Assume branching scenario below Merging: What is a 3-way Merge? C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 47. 47 © 2016 Brent Laster 47 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot) Merging: What is a 3-way Merge? C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 48. 48 © 2016 Brent Laster 48 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature Merging: What is a 3-way Merge? C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 49. 49 © 2016 Brent Laster 49 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5) Merging: What is a 3-way Merge? C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 50. 50 © 2016 Brent Laster 50 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor Merging: What is a 3-way Merge? C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 51. 51 © 2016 Brent Laster 51 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor Merging: What is a 3-way Merge? $ git checkout master C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 52. 52 © 2016 Brent Laster 52 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor Merging: What is a 3-way Merge? $ git checkout master $ git merge feature C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 53. 53 © 2016 Brent Laster 53 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor Merging: What is a 3-way Merge? $ git checkout master $ git merge feature C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 54. 54 © 2016 Brent Laster 54 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor Merging: What is a 3-way Merge? $ git checkout master $ git merge feature C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 55. 55 © 2016 Brent Laster 55 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor Merging: What is a 3-way Merge? $ git checkout master $ git merge feature C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 56. 56 © 2016 Brent Laster 56 @BrentCLaster  Assume branching scenario below  master and feature branches have both diverged (changed) since their last common ancestor (commit/snapshot)  Intent is to change to master and merge in feature  Current commit on target branch isn’t a direct ancestor of current commit on branch you’re merging in (i.e. C4 isn’t on the same line of development as C5)  Git does 3-way merge using common ancestor  Instead of just moving branch pointer forward, Git creates a new snapshot and a new commit that points to it called a “merge commit” Merging: What is a 3-way Merge? $ git checkout master $ git merge feature C2 C3 C4 C5 feature C0 C1 Common Ancestor Branch Tip Branch Tip master
  • 57. 57 © 2016 Brent Laster 57 @BrentCLaster Merging: What is a Rebase? C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 58. 58 © 2016 Brent Laster 58 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one. C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 59. 59 © 2016 Brent Laster 59 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]): C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 60. 60 © 2016 Brent Laster 60 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base) C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 61. 61 © 2016 Brent Laster 61 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 62. 62 © 2016 Brent Laster 62 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 63. 63 © 2016 Brent Laster 63 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)” C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 64. 64 © 2016 Brent Laster 64 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process: C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 65. 65 © 2016 Brent Laster 65 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process: $ git checkout feature $ git rebase master C3 C4 C5 C0 Common Ancestor C2 feature C1 master
  • 66. 66 © 2016 Brent Laster 66 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process:  Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing onto) $ git checkout feature $ git rebase master C3 C4 C5 C0 Common Ancestor C2 feature C1 C2 master
  • 67. 67 © 2016 Brent Laster 67 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process:  Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing onto)  Gets the diff introduced by each commit of the branch you are on, saving them to temporary files $ git checkout feature $ git rebase master C3 C4 C5 C0 Common Ancestor C2 feature C1 C2 master
  • 68. 68 © 2016 Brent Laster 68 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process:  Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing onto)  Gets the diff introduced by each commit of the branch you are on, saving them to temporary files  Applies each change in turn $ git checkout feature $ git rebase master C3 C4 C5 C0 Common Ancestor C2 feature C1 C3’ C5’C2 master
  • 69. 69 © 2016 Brent Laster 69 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process:  Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing onto)  Gets the diff introduced by each commit of the branch you are on, saving them to temporary files  Applies each change in turn  Moves the branch to the new rebase point $ git checkout feature $ git rebase master C3 C4 C5 C0 Common Ancestor C2 feature C1 C3’ C5’C2 master
  • 70. 70 © 2016 Brent Laster 70 @BrentCLaster Merging: What is a Rebase?  Rebase – take all of the changes that were committed on one branch and replay them on another one.  Concepts in simple syntax (git rebase branch2 [branch1]):  Move branchpoint of branch (carrying along all commits) to be off of a different commit (new base)  Current branch (or branch1 if supplied) is one having its branchpoint moved  Branch2 (or commit) provided as first/only argument is the new branchpoint  In simple case, think of it as “pick up branch1 entirely and move its branchpoint to be after the tip of branch2)”  Process:  Goes to the common ancestor of the two branches (the one you are on and the one you are rebasing onto)  Gets the diff introduced by each commit of the branch you are on, saving them to temporary files  Applies each change in turn  Moves the branch to the new rebase point $ git checkout feature $ git rebase master C3 C4 C5 C0 Common Ancestor C2 feature C1 C3’ C5’C2 master
  • 71. 71 © 2016 Brent Laster 71 @BrentCLaster Command: Git Stash  Purpose -- allow you to keep a backup copy of your work that hasn’t been committed yet  Use case - you want to switch branches but don’t want to lose work that hasn’t been committed; you want to save something you’ve tried and may want to come back to  Syntax:
  • 72. 72 © 2016 Brent Laster 72 @BrentCLaster Stash
  • 73. 73 © 2016 Brent Laster 73 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory
  • 74. 74 © 2016 Brent Laster 74 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory*
  • 75. 75 © 2016 Brent Laster 75 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory* *
  • 76. 76 © 2016 Brent Laster 76 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory* * > git stash
  • 77. 77 © 2016 Brent Laster 77 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory* * > git stash
  • 78. 78 © 2016 Brent Laster 78 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{0} > git stash
  • 79. 79 © 2016 Brent Laster 79 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * ** stash@{0} > git stash
  • 80. 80 © 2016 Brent Laster 80 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * ** ** stash@{0} > git stash
  • 81. 81 © 2016 Brent Laster 81 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * ** ** stash@{0} > git stash #
  • 82. 82 © 2016 Brent Laster 82 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * ** ** stash@{0} > git stash> git stash -u #
  • 83. 83 © 2016 Brent Laster 83 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# stash@{0} stash@{0} stash@{1} > git stash -u
  • 84. 84 © 2016 Brent Laster 84 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# *** stash@{0} stash@{0} stash@{1} > git stash -u
  • 85. 85 © 2016 Brent Laster 85 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# *** *** stash@{0} stash@{0} stash@{1} > git stash -u
  • 86. 86 © 2016 Brent Laster 86 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# *** *** stash@{0} stash@{0} stash@{1} > git stash save “cool feature”
  • 87. 87 © 2016 Brent Laster 87 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# stash@{0} Staging Area *** stash@{2} stash@{1} stash@{0} stash@{0}stash@{1} stash@{1}stash@{2} “cool feature” Working Directory ***
  • 88. 88 © 2016 Brent Laster 88 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# stash@{0} Staging Area *** stash@{2} stash@{1} stash@{0} stash@{0}stash@{1} stash@{1}stash@{2} “cool feature” Working Directory *** > git stash apply stash@{1}
  • 89. 89 © 2016 Brent Laster 89 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# stash@{0} Staging Area *** stash@{2} ** ** stash@{1} stash@{0} stash@{0}stash@{1} stash@{1}stash@{2} “cool feature” Working Directory *** # > git stash apply stash@{1}
  • 90. 90 © 2016 Brent Laster 90 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory stash@{0} Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# stash@{0} Staging Area *** stash@{2} ** ** stash@{1} stash@{0} stash@{0}stash@{1} stash@{1}stash@{2} “cool feature” Working Directory *** # $ git stash pop stash@{2}
  • 91. 91 © 2016 Brent Laster 91 @BrentCLaster Stash Staging Area Staging Area Local Repository Working Directory Staging Area * Working Directory * stash@{1} Staging Area ** Working Directory **# stash@{0} Staging Area *** *** *** stash@{0}stash@{1} “cool feature” Working Directory *** # $ git stash pop stash@{2}
  • 92. 92 © 2016 Brent Laster 92 @BrentCLaster Command: Git Reset  Purpose -- allow you to “roll back” so that your branch points at a previous commit ; optionally also update staging area and working directory to that commit  Use case - you want to update your local environment back to a previous point in time; you want to overwrite or a local change you’ve made  Syntax:  Warning: --hard overwrites everything
  • 93. 93 © 2016 Brent Laster 93 @BrentCLaster Command: Git Revert  Purpose -- allow you to “undo” by adding a new change that cancels out effects of previous one  Use case - you want to cancel out a previous change but not roll things back  Syntax:  Note: The net result of using this command vs. reset can be the same. If so, and content that is being reset/revert has been pushed such that others may be consuming it, preference is for revert.
  • 94. 94 © 2016 Brent Laster 94 @BrentCLaster Local Repository Reset and Revert Line 1 Staging Area Working Directory XYZ ABC Line 1 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 Line 1 Line 2 Line 1Line 1 Line 1 Line 2 tag: current
  • 95. 95 © 2016 Brent Laster 95 @BrentCLaster Local Repository git reset --hard 87ba8bc Reset and Revert Line 1 Staging Area Working Directory XYZ ABC Line 1 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 Line 1 Line 2 Line 1 Line 1 Line 1 Line 2 tag: current
  • 96. 96 © 2016 Brent Laster 96 @BrentCLaster Local Repository git reset --hard 87ba8bc Reset and Revert Line 1 Staging Area Working Directory XYZ ABC Line 1 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 Line 1 Line 2 Line 1 Line 1 Line 1 Line 2 tag: current
  • 97. 97 © 2016 Brent Laster 97 @BrentCLaster Local Repository git reset current~1 [--mixed] Reset and Revert Line 1 Staging Area Working Directory XYZ ABC Line 1 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 Line 1 Line 2 Line 1 Line 1 Line 1 Line 2 tag: current
  • 98. 98 © 2016 Brent Laster 98 @BrentCLaster Local Repository git reset current~1 [--mixed] Reset and Revert Line 1 Staging Area Working Directory 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 Line 1 Line 1 Line 2 tag: current
  • 99. 99 © 2016 Brent Laster 99 @BrentCLaster Local Repository git revert HEAD~1 Reset and Revert Line 1 Staging Area Working Directory 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 Line 1 Line 2 Line 1 Line 1 Line 2 tag: current
  • 100. 100 © 2016 Brent Laster 100 @BrentCLaster Local Repository git revert HEAD~1 Reset and Revert Line 1 Staging Area Working Directory 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 c1c8bd4 Line 1 Line 2 Line 1 Line 1 Line 2 tag: current
  • 101. 101 © 2016 Brent Laster 101 @BrentCLaster Local Repository Reset and Revert Line 1 Staging Area Working Directory 87ba8bc 43bd3ef d21be2c Line 1 Line 2 Line 3 c1c8bd4 Line 1 Line 2 Line 1 Line 1 Line 2 tag: current
  • 102. 102 © 2016 Brent Laster 102 @BrentCLaster Command: Git Rerere (Reuse Recorded Resolution)  Purpose -- allows recording of how you solve a merge situation and then can automatically resolve the same situation in the same way if needed later  Use case - trial and repeated merges; merging newer versions of a branch with the same conflicts into a newer one periodically; resolve conflicts after reset or revert; applicable to any repeated merge case: rebase, merge  Syntax:  Note: This is a “state” command. Enabled by turning on a state in Git, rather than just running a command  Enabled via git config --global rerere.enabled 1 » Then runs automatically  Invoked directly via git rerere for related commands or options
  • 103. 103 © 2016 Brent Laster 103 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File BFile B File A File C Git Rerere 1
  • 104. 104 © 2016 Brent Laster 104 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File BFile B File A File C Git Rerere 1
  • 105. 105 © 2016 Brent Laster 105 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File BFile B File A File C rr-cache Git Rerere 1
  • 106. 106 © 2016 Brent Laster 106 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C rr-cache Git Rerere 1
  • 107. 107 © 2016 Brent Laster 107 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File A File CFile A File C rr-cache Git Rerere 1
  • 108. 108 © 2016 Brent Laster 108 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File A File CFile A File C rr-cache File A File C Git Rerere 1
  • 109. 109 © 2016 Brent Laster 109 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File A File CFile A File C rr-cache File A File C File B <<>> preimage Git Rerere 1
  • 110. 110 © 2016 Brent Laster 110 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File A File CFile A File C rr-cache File A File C File B <<>> preimage Git Rerere 1
  • 111. 111 © 2016 Brent Laster 111 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File A File CFile A File C rr-cache File A File C File B <<>> preimage Git Rerere 1
  • 112. 112 © 2016 Brent Laster 112 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File BFile A File CFile A File C rr-cache File A File C File B <<>> preimage Git Rerere 1
  • 113. 113 © 2016 Brent Laster 113 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B File A File CFile BFile A File C rr-cache File A File C File B <<>> preimage Git Rerere 1
  • 114. 114 © 2016 Brent Laster 114 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C File B File A File C rr-cache File A File C File B <<>> preimage Git Rerere 1
  • 115. 115 © 2016 Brent Laster 115 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C File B File A File C rr-cache File A File C File B <<>> preimage postimage Git Rerere 1
  • 116. 116 © 2016 Brent Laster 116 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C File B File A File C rr-cache File A File C File B <<>> preimage postimage File B Git Rerere 1
  • 117. 117 © 2016 Brent Laster 117 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C File B File A File C rr-cache File A File C File B <<>> preimage postimage File B Git Rerere 1
  • 118. 118 © 2016 Brent Laster 118 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C File B File A File C rr-cache File A File C File B <<>> preimage postimage File B Git Rerere 1
  • 119. 119 © 2016 Brent Laster 119 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File BFile B File A File C rr-cache File B <<>> preimage postimage File B Git Rerere 2
  • 120. 120 © 2016 Brent Laster 120 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File BFile B File A File C rr-cache File B <<>> preimage postimage File B Git Rerere 2
  • 121. 121 © 2016 Brent Laster 121 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File B <<>> File A File CFile A File C rr-cache File A File C File B <<>> preimage postimage File B Git Rerere 2
  • 122. 122 © 2016 Brent Laster 122 © 2016 Brent Laster@BrentCLaster Local Repository feature Staging Area File B Working Directory File C File A File B master File A File C File B File A File C File A File C File B File A File C rr-cache File A File C File B <<>> preimage postimage File B Git Rerere 2
  • 123. 123 © 2016 Brent Laster 123 @BrentCLaster Command: Bisect  Purpose - Use “automated” binary search through Git’s history to find a specific commit that first introduced a problem (i.e. “first bad commit”)  Use case - Quickly locate the commit in Git’s history that introduced a bug  Syntax:
  • 124. 124 © 2016 Brent Laster 124 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 125. 125 © 2016 Brent Laster 125 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest versionVersion 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 126. 126 © 2016 Brent Laster 126 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest versionVersion 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 127. 127 © 2016 Brent Laster 127 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest version  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 128. 128 © 2016 Brent Laster 128 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest version  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 129. 129 © 2016 Brent Laster 129 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest version  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 130. 130 © 2016 Brent Laster 130 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest version  try code  git bisect start Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 131. 131 © 2016 Brent Laster 131 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 132. 132 © 2016 Brent Laster 132 @BrentCLaster LOCAL REPOSITORY Version 1Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 133. 133 © 2016 Brent Laster 133 @BrentCLaster LOCAL REPOSITORY Version 1 Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 134. 134 © 2016 Brent Laster 134 @BrentCLaster LOCAL REPOSITORY Version 1 Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 135. 135 © 2016 Brent Laster 135 @BrentCLaster LOCAL REPOSITORY Version 1 Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 136. 136 © 2016 Brent Laster 136 @BrentCLaster LOCAL REPOSITORY Version 1 Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 137. 137 © 2016 Brent Laster 137 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 138. 138 © 2016 Brent Laster 138 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 139. 139 © 2016 Brent Laster 139 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 140. 140 © 2016 Brent Laster 140 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 5 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 141. 141 © 2016 Brent Laster 141 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 142. 142 © 2016 Brent Laster 142 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 143. 143 © 2016 Brent Laster 143 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 144. 144 © 2016 Brent Laster 144 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 7 Version 6 WORKING DIRECTORY
  • 145. 145 © 2016 Brent Laster 145 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code  git bisect bad (bisect checks out version 6) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 6 WORKING DIRECTORY
  • 146. 146 © 2016 Brent Laster 146 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code  git bisect bad (bisect checks out version 6)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 6 WORKING DIRECTORY
  • 147. 147 © 2016 Brent Laster 147 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code  git bisect bad (bisect checks out version 6)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 6 WORKING DIRECTORY
  • 148. 148 © 2016 Brent Laster 148 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code  git bisect bad (bisect checks out version 6)  try code Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 6 WORKING DIRECTORY
  • 149. 149 © 2016 Brent Laster 149 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code  git bisect bad (bisect checks out version 6)  try code  git bisect bad (git reports version 6 as the first bad commit) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 6 WORKING DIRECTORY
  • 150. 150 © 2016 Brent Laster 150 @BrentCLaster LOCAL REPOSITORY Version 1 Bisect  checkout latest version  try code  git bisect start  git bisect bad  checkout earlier version ( user checks out)  try code  git bisect good (bisect checks out version 5)  try code  git bisect good (bisect checks out version 7)  try code  git bisect bad (bisect checks out version 6)  try code  git bisect bad (git reports version 6 as the first bad commit) Version 3 Version 4 Version 5 Version 6 Version 7 Version 8 Version 9 Version 10 Version 2 Version 6 FIRST BAD COMMIT WORKING DIRECTORY
  • 151. 151 © 2016 Brent Laster 151 @BrentCLaster Background: Switching between Branches Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 152. 152 © 2016 Brent Laster 152 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 153. 153 © 2016 Brent Laster 153 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 154. 154 © 2016 Brent Laster 154 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 155. 155 © 2016 Brent Laster 155 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch> Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 156. 156 © 2016 Brent Laster 156 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch>  Reverts files in working directory to snapshot pointed to by <branch> Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 157. 157 © 2016 Brent Laster 157 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch>  Reverts files in working directory to snapshot pointed to by <branch>  Updates indicators Local Repository Working Directory 87ba8bc 43bd3ef d21be2c c1c8bd4
  • 158. 158 © 2016 Brent Laster 158 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch>  Reverts files in working directory to snapshot pointed to by <branch>  Updates indicators  git branch Local Repository Working Directory * 87ba8bc 43bd3ef d21be2c c1c8bd4 master testing
  • 159. 159 © 2016 Brent Laster 159 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch>  Reverts files in working directory to snapshot pointed to by <branch>  Updates indicators git checkout testing  git branch Local Repository Working Directory * 87ba8bc 43bd3ef d21be2c c1c8bd4 master testing
  • 160. 160 © 2016 Brent Laster 160 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch>  Reverts files in working directory to snapshot pointed to by <branch>  Updates indicators git checkout testing git checkout master  git branch Local Repository Working Directory * 87ba8bc 43bd3ef d21be2c c1c8bd4 master testing
  • 161. 161 © 2016 Brent Laster 161 @BrentCLaster Background: Switching between Branches Command: git checkout <branch> git checkout master  Does three things  Moves HEAD pointer back to <branch>  Reverts files in working directory to snapshot pointed to by <branch>  Updates indicators git checkout testing git checkout master git checkout testing  git branch Local Repository Working Directory * 87ba8bc 43bd3ef d21be2c c1c8bd4 master testing
  • 162. 162 © 2016 Brent Laster 162 @BrentCLaster Command: Worktrees  Purpose - Allows multiple, separate Working Areas attached to one Local Repository  Use case - Simultaneous development in multiple branche  Syntax  git worktree add [-f] [--detach] [-b <new-branch>] <path> [<branch>]  git worktree list [--porcelain]  git worktree prune [-n] [-v] [--expire <expire>]  Notes  “Traditional” working directory is called the main working tree; Any new trees you create with this command are called linked working trees  Information about working trees is stored in the .git area (assuming .git default GIT_DIR is used)  Working tree information is stored in .git/worktrees/<name of worktree>.
  • 163. 163 © 2016 Brent Laster 163 @BrentCLaster Worktrees Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine
  • 164. 164 © 2016 Brent Laster 164 @BrentCLaster Worktrees  git worktree add -b exp tree1 Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine
  • 165. 165 © 2016 Brent Laster 165 @BrentCLaster Worktrees  git worktree add -b exp tree1 Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine worktrees/ tree1
  • 166. 166 © 2016 Brent Laster 166 @BrentCLaster Worktrees  git worktree add -b exp tree1 Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine worktrees/ tree1
  • 167. 167 © 2016 Brent Laster 167 @BrentCLaster Worktrees  git worktree add -b exp tree1 Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine worktrees/ tree1 gitdir HEAD etc.
  • 168. 168 © 2016 Brent Laster 168 @BrentCLaster Worktrees  git worktree add -b exp tree1 Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine worktrees/ tree1 gitdir HEAD etc. tree1 Linked Working Tree Staging Area Working Directory (exp)
  • 169. 169 © 2016 Brent Laster 169 @BrentCLaster Worktrees  git worktree add -b exp tree1  git worktree add -b prod tree2 Remote Repository Main Working Tree Server Add Commit Push Pull Staging Area Local Repository Working Directory (master) Local Machine worktrees/ tree1 gitdir HEAD etc. tree1 Linked Working Tree Staging Area Working Directory (exp) gitdir HEAD etc. tree2 Linked Working Tree Staging Area Working Directory (prod) tree2
  • 170. 170 © 2016 Brent Laster 170 @BrentCLaster Command: Submodules  Purpose - Allows including a separate repository with your current repository  Use case - include the Git repository for one or more dependencies along with the original repository for a project  Syntax git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>] git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…​] git submodule [--quiet] init [--] [<path>…​] git submodule [--quiet] deinit [-f|--force] [--] <path>…​ git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--] [<path>…​] git submodule [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>] [commit] [--] [<path>…​] git submodule [--quiet] foreach [--recursive] <command> git submodule [--quiet] sync [--recursive] [--] [<path>…​]  Notes  Creates a subdirectory off of your original repository that contains a clone of another Git repository  Original repository is typically called superproject  Metadata stored in .gitmodules file
  • 171. 171 © 2016 Brent Laster 171 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Submodules 1
  • 172. 172 © 2016 Brent Laster 172 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory What happens when you add a submodule? Submodules 1
  • 173. 173 © 2016 Brent Laster 173 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository What happens when you add a submodule? Submodules 1
  • 174. 174 © 2016 Brent Laster 174 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. Submodules 1
  • 175. 175 © 2016 Brent Laster 175 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. Submodules 1
  • 176. 176 © 2016 Brent Laster 176 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. Submodules 1
  • 177. 177 © 2016 Brent Laster 177 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. Submodules 1
  • 178. 178 © 2016 Brent Laster 178 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. Submodules 1
  • 179. 179 © 2016 Brent Laster 179 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. .gitmodules Submodules 1
  • 180. 180 © 2016 Brent Laster 180 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. .gitmodules Submodules 1
  • 181. 181 © 2016 Brent Laster 181 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. .gitmodules Submodules 1
  • 182. 182 © 2016 Brent Laster 182 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. .gitmodules Submodules 1
  • 183. 183 © 2016 Brent Laster 183 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. .gitmodules Submodules 1
  • 184. 184 © 2016 Brent Laster 184 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. .gitmodules mod1 <current commit> Submodules 1
  • 185. 185 © 2016 Brent Laster 185 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. .gitmodules mod1 <current commit> Submodules 1
  • 186. 186 © 2016 Brent Laster 186 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: .gitmodules mod1 <current commit> Submodules 1
  • 187. 187 © 2016 Brent Laster 187 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: 7. Commit modules/ mod1 gitdir HEAD etc. Submodules 1
  • 188. 188 © 2016 Brent Laster 188 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: 7. Commit modules/ mod1 gitdir HEAD etc. submodule reference Submodules 1
  • 189. 189 © 2016 Brent Laster 189 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: 7. Commit modules/ mod1 gitdir HEAD etc. submodule reference commit pointed to by submodule reference Submodules 1
  • 190. 190 © 2016 Brent Laster 190 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: 7. Commit modules/ mod1 gitdir HEAD etc. submodule reference commit pointed to by submodule reference Head of branch Submodules 1
  • 191. 191 © 2016 Brent Laster 191 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: 7. Commit modules/ mod1 gitdir HEAD etc. submodule reference commit pointed to by submodule reference Head of branch 8. Push Submodules 1
  • 192. 192 © 2016 Brent Laster 192 @BrentCLaster Remote Repository proj_dir superproject Staging Area Local Repository Working Directory Remote Repository proj_dir/mod1 submodule 1 Staging Area Working Directory Local Repository What happens when you add a submodule? 1. Git clones down the repository for the submodule into the current directory. 2. By default, Git checks out the master branch. 3. Git adds the submodule’s path for cloning to the .gitmodules file. 4. Git adds the .gitmodules file to the index, ready to be committed. 5. Git adds the current commit ID of the submodule to the index, ready to be committed. 6. To complete the add process, you need to complete the Git workflow for the staged changes. From the superproject’s directory: 7. Commit modules/ mod1 gitdir HEAD etc. submodule reference commit pointed to by submodule reference Head of branch 8. Push Submodules 1
  • 193. 193 © 2016 Brent Laster 193 @BrentCLaster Remote Repository How do we clone a repository with submodules? Submodules 2
  • 194. 194 © 2016 Brent Laster 194 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 modules/ mod1 gitdir HEAD etc. How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty Submodules 2
  • 195. 195 © 2016 Brent Laster 195 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 modules/ mod1 gitdir HEAD etc. How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty 2. git submodule init - puts submodule location information in superproject’s config file Remote Repository Submodules 2
  • 196. 196 © 2016 Brent Laster 196 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 modules/ mod1 gitdir HEAD etc. How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty 2. git submodule init - puts submodule location information in superproject’s config file Remote Repository Submodules 2
  • 197. 197 © 2016 Brent Laster 197 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 modules/ mod1 gitdir HEAD etc. How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty 2. git submodule init - puts submodule location information in superproject’s config file Remote Repository 3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project Submodules 2
  • 198. 198 © 2016 Brent Laster 198 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty 2. git submodule init - puts submodule location information in superproject’s config file Remote Repository 3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project Submodules 2
  • 199. 199 © 2016 Brent Laster 199 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty 2. git submodule init - puts submodule location information in superproject’s config file Remote Repository 3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project submodule reference Submodules 2
  • 200. 200 © 2016 Brent Laster 200 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch How do we clone a repository with submodules? 1. git clone - puts in structure - but submodules areas are empty 2. git submodule init - puts submodule location information in superproject’s config file Remote Repository 3. git submodule update - actually clones repositories for submodules into the corresponding subdirectories and checks out the indicated commits for the containing project Note: Shortcuts - git submodule update --init and git clone --recursive or --recurse-submodules submodule reference Submodules 2
  • 201. 201 © 2016 Brent Laster 201 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference Incorporating updates to submodules: Submodules 3
  • 202. 202 © 2016 Brent Laster 202 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: Submodules 3
  • 203. 203 © 2016 Brent Laster 203 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can Submodules 3
  • 204. 204 © 2016 Brent Laster 204 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull Submodules 3
  • 205. 205 © 2016 Brent Laster 205 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull Submodules 3
  • 206. 206 © 2016 Brent Laster 206 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull Submodules 3
  • 207. 207 © 2016 Brent Laster 207 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull Submodules 3
  • 208. 208 © 2016 Brent Laster 208 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master Submodules 3
  • 209. 209 © 2016 Brent Laster 209 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR Submodules 3
  • 210. 210 © 2016 Brent Laster 210 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote Submodules 3
  • 211. 211 © 2016 Brent Laster 211 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3
  • 212. 212 © 2016 Brent Laster 212 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3
  • 213. 213 © 2016 Brent Laster 213 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 214. 214 © 2016 Brent Laster 214 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 215. 215 © 2016 Brent Laster 215 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 216. 216 © 2016 Brent Laster 216 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated .gitmodules mod1 <current commit> Submodules 3 3. To update: add, commit, and push reference changes.
  • 217. 217 © 2016 Brent Laster 217 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 218. 218 © 2016 Brent Laster 218 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 219. 219 © 2016 Brent Laster 219 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 220. 220 © 2016 Brent Laster 220 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 221. 221 © 2016 Brent Laster 221 @BrentCLaster Remote Repository main superproject Staging Area Local Repository Working Directory main/mod1 submodule 1 Staging Area Working Directory Local Repository modules/ mod1 gitdir HEAD etc. commit pointed to by submodule reference Head of branch Remote Repository submodule reference new commitIncorporating updates to submodules: 1. You can $ cd mod1; git checkout <branch> ; git pull OR $ git pull --recurse-submodules; cd <module dir>; git merge origin/master OR $ git submodule update --remote 2. Although module has been updated, references that the superproject has to it haven’t been updated Submodules 3 3. To update: add, commit, and push reference changes.
  • 222. 222 © 2016 Brent Laster 222 @BrentCLaster Submodule - Challenges  Challenges around using submodules nearly always involve keeping submodule content (and “current” commit) in sync with submodule references in superproject  If references are wrong, operations like “git submodule update” will backlevel submodule content to commits in reference  If these references are out of sync and that inconsistency is pushed to the remote for the superproject, then other users that pull that version of the superproject can end up back-leveling their submodules, even if they’ve updated their superproject before.
  • 223. 223 © 2016 Brent Laster 223 @BrentCLaster Command: Subtrees  Purpose - Allows including a copy of a separate repository with your current repository  Use case - include a copy of a Git repository for one or more dependencies along with the original repository for a project  Syntax  Notes  No links like a submodule - just a copy in a subdirectory  Advantage - no links to maintain  Disadvantage - extra content to carry around with your project git subtree add -P <prefix> <commit> git subtree add -P <prefix> <repository> <ref> git subtree pull -P <prefix> <repository> <ref> git subtree push -P <prefix> <repository> <ref> git subtree merge -P <prefix> <commit> git subtree split -P <prefix> [OPTIONS] [<commit>]
  • 224. 224 © 2017 Brent Laster 22 4 Subtrees Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj)
  • 225. 225 © 2017 Brent Laster 22 5 Subtrees  Adding a copy from a remote as a subtree Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj)
  • 226. 226 © 2017 Brent Laster 22 6 Subtrees  Adding a copy from a remote as a subtree  cd myproject Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj)
  • 227. 227 © 2017 Brent Laster 22 7 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj)
  • 228. 228 © 2017 Brent Laster 22 8 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 229. 229 © 2017 Brent Laster 22 9 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 230. 230 © 2017 Brent Laster 23 0 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 231. 231 © 2017 Brent Laster 23 1 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it  branch (master) is optional Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 232. 232 © 2017 Brent Laster 23 2 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it  branch (master) is optional  directory listing of myproject now shows subproj as subdirectory Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 233. 233 © 2017 Brent Laster 23 3 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it  branch (master) is optional  directory listing of myproject now shows subproj as subdirectory Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 234. 234 © 2017 Brent Laster 23 4 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it  branch (master) is optional  directory listing of myproject now shows subproj as subdirectory  Looking in the logs of the subproject will show the squashed history Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 235. 235 © 2017 Brent Laster 23 5 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it  branch (master) is optional  directory listing of myproject now shows subproj as subdirectory  Looking in the logs of the subproject will show the squashed history Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository
  • 236. 236 © 2017 Brent Laster 23 6 Subtrees  Adding a copy from a remote as a subtree  cd myproject  git subtree add --prefix subproject --squash subproj.git master  Use “prefix” option to specify path for subproject  Use “squash” option to compress history from remote before adding it  branch (master) is optional  directory listing of myproject now shows subproj as subdirectory  Looking in the logs of the subproject will show the squashed history  To get the latest, use pull Remote Repository myproject superproject superproject Staging Area (myproject) Local Repository Working Directory Remote Repository (subproj) myproject/subproject subtree Staging Area Working Directory Local Repository

Notas do Editor

  1. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  2. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  3. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  4. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  5. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  6. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  7. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  8. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  9. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  10. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  11. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  12. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  13. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  14. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  15. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  16. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  17. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  18. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  19. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  20. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  21. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  22. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  23. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  24. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  25. Merge commit is special because it has multiple parents Git determines best common ancestor to use for its merge base
  26. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  27. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  28. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  29. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  30. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  31. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  32. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  33. As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.
  34. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  35. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  36. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  37. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  38. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  39. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  40. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  41. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  42. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  43. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.
  44. This also means the changes you make from this point forward will diverge from an older version of the project. It essentially rewinds the work you’ve done in your testing branch temporarily so you can go in a different direction.