Download Lecture 3 Branches and more Summaries History in PDF only on Docsity!
Lecture 3
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
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
Activity!
git branch Example use: git branch
- Lists all the local branches in the current repository and marks which branch you’re currently on - Where are “you”? Well, you’re always at HEAD. Usually, you’re also at a branch as well.
- The default branch in a repository is called “master”
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
- More on this next lecture
Commits are made on whatever branch you’re on 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
- git checkout experiment master HEAD experiment
Commits are made on whatever branch you’re on B A
- 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”
- git branch wildidea 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 experiment HEAD 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”
- git checkout master 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”
- git checkout master
- git commit – m “F” master HEAD experiment wildidea