AGENDA
- Branching
- Merging
- Handling conflicts
- Stash
- Log visualization
- Blame
- Mini exercises
Branching
- Branch = parallel line of development
- Default branch is usually
main
git branch feature
git switch feature
Working in a Branch
echo "new feature" > feature.txt
git add feature.txt
git commit -m "Add feature file"
git switch main
Merging
- Bring changes from another branch into current one
Merge Conflicts
- Happen when two branches modify the same line
- Git marks conflicts in files:
<<<<<<< HEAD
line from main
=======
line from feature
>>>>>>> feature
git add conflicted_file.cpp
git commit
Log Visualization
git log --oneline --graph --all
Stash
- Save unfinished changes temporarily
git stash # save changes
git pull # update repo
git stash pop # reapply changes
Blame
- Show who last modified each line in a file
Mini-Exercises
Exercise 1
- Create a new branch
experiment
- Add and commit a new file
- Switch back to
main and merge experiment
Exercise 2 (Merge)
- Make a new branch
b1
- Commit change
- Go back to
main and make another branch b2
- Commit change
- Switch back to
b1
- Merge
b2
- Commit
Exercise 3
- Run
git blame on a file with multiple commits
- Identify who changed each line
Survival Package (Git Advanced)
git branch
git switch
git merge
- Conflict resolution markers
<<<<<<<, =======, >>>>>>>
git stash
git stash pop
git log --oneline --graph
git blame
Wrap-Up
- Learned branching and merging
- Practiced conflict resolution
- Used stash for temporary changes
- Investigated file history with blame
Next Session
- Start with C++ basics
- First project with g++, Makefile, and CMake