gitBlock 2.3: Branches & Merging
git branchesBackground: https://unsplash.com/photos/V1YEEItoOTE
main branchNote
The default branch used to be called master and was then changed to main (next slide).
master vs. main ⚙️The default branch used to be called master, this was more-or-less recently changed to main, but not all repositories / git installations have changed yet.
Whether git on your computer uses master or main depends on when it was installed.
Example of a repository history with branching
git checkout -b my-branch ✅
git branch my-branch ❌
mainYou can switch branches with git checkout (as we’ve already done earlier)
Tip
There’s no more -b when the branch already exists
Note
You can also use git switch my-branch, but this command is still experimental right now and may change.
git merge my-branch
main branch when using git merge (but not always!)Note
Only branches with a shared history can be merged, but this should (almost) always be the case.
Example of a merged repository history
git-exercisenew-featuregit statusmainnew-feature branch into maingit: Merge ConflictsPhoto by Chris Sabor on Unsplash
git is very smart in the way it combines changes from two branches
And how to avoid it.
The merge conflict arises because both branches change the same line
We could’ve avoided the merge conflict, by merging main into feature before doing the change on feature
guessing_conflict.txtguesses and check it out
git statusWrite your guess below the line with the matching letter.
main branch againgit merge to merge the guesses branch into your main branchMerging

Rebasing

Any Questions?