git
Block 2.3: Branches & Merging
git branches
Background: https://unsplash.com/photos/V1YEEItoOTE
main
branchNote
The default branch used to be called master
, this was more-or-less recently changed to main
, but not all repositories have changed yet.
git checkout -b my-branch
✅
git branch my-branch
❌
main
You 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.
Background: https://giphy.com/gifs/berlin-demo-govid-loAFGkJxYzgxu3NKnZ
git-exercise
new-feature
git status
main
new-feature
branch into main
git
: Merge Conflictsgit
is very smart in the way it combines changes from two branches
And how to avoid it.
guessing_conflict.txt
guesses
and check it out
git status
Write 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?