Download Lecture 4 Branches and more Exercises Data Structures and Algorithms in PDF only on Docsity!
Lecture 4
Branches
Sign in on the attendance sheet!
Last Time
Scenario: You work on two features at once in
a project
b4e2c29: initial commit b5f3729: even more work on feature A 8277e09: even more work on feature B 8b7d883: begin work on feature B 8fc42c6: begin work on feature A 6f96cf3: more work on feature A e167179: more work on feature B master, HEAD
- Hard to distinguish the two different features that are being worked on based on the git history
- If the features are related, the commits might interfere with each other
Solution: Non-linear development via
branches
8b7d883: begin work on feature B 8fc42c6: begin work on feature A 6f96cf3: more work on feature A e167179: more work on feature B b4e2c29: initial commit b5f3729: even more work on feature A 8277e09: even more work on feature B master featureA featureB, HEAD
git branch
Example use: git branch develop
- Creates a new branch called “develop” that points to wherever you are right now (i.e. wherever HEAD is right now)
git checkout
Example use: git checkout develop
- Switches to the branch named “develop”
- Instead of a branch name, you can also put a commit hash
- Very different from “git checkout ” (from last week)! That checkouts a single file, this checkouts the entire branch, including all of its files
Commits are made on whatever branch
you’re on
B A
- git commit – m “A”
- git commit – m “B” master HEAD
Commits are made on whatever branch
you’re on
B A
- git commit – m “A”
- git commit – m “B”
- git branch experiment master HEAD experiment
Commits are made on whatever branch
you’re on
B A C
- git commit – m “A”
- git commit – m “B”
- git branch experiment
- git checkout experiment
- git commit – m “C” master experiment HEAD
Commits are made on whatever branch
you’re on
B A C D
- git commit – m “A”
- git commit – m “B”
- git branch experiment
- git checkout experiment
- git commit – m “C”
- git commit – m “D” master experiment HEAD
Commits are made on whatever branch
you’re on
B A C D
- git commit – m “A”
- git commit – m “B”
- git branch experiment
- git checkout experiment
- git commit – m “C”
- git commit – m “D”
- git branch wildidea
- git checkout wildidea master HEAD experiment wildidea
Commits are made on whatever branch
you’re on
B A C D E
- git commit – m “A”
- git commit – m “B”
- git branch experiment
- git checkout experiment
- git commit – m “C”
- git commit – m “D”
- git branch wildidea
- git checkout wildidea
- git commit – m “E” master HEAD experiment wildidea
Commits are made on whatever branch
you’re on
B A C D E F
- git commit – m “A”
- git commit – m “B”
- git branch experiment
- git checkout experiment
- git commit – m “C”
- git commit – m “D”
- git branch wildidea
- git checkout wildidea
- git commit – m “E”
- git checkout master
- git commit – m “F” master HEAD experiment wildidea
Exercise: What [directed, acyclic] graph do the following
git commands produce?
- git commit – m “A”
- git commit – m “B”
- git branch stable
- git branch experiment
- git checkout experiment
- git commit – m “C”
- git checkout master
- git commit – m “D”
- git branch goodidea
- git checkout experiment
- git branch whereami
- git commit – m “E”
- git checkout goodidea
- git checkout master
- git commit – m “F”
- git checkout whereami
- git commit – m “G”
- git checkout master B A C D E F stable experiment goodidea master, HEAD G whereami