git
Block 1.3: Branches, Merging & More
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.
You can also squash all commits from another branch together when merging.
git merge --squash <branch>
Merging
Merged (--squash
)
git-example
feature/vegeterian
git status
main
feature/vegeterian
branch into main
git
: Merge Conflictsgit
is very smart in the way it combines changes from two branches
And how to avoid it.
Background: https://giphy.com/gifs/iontelevision-fire-chicago-hose-qkTA7B5umJaEwnQ3bW
my-turn
and check it out
git status
For each of the three rounds, write your choice of rock 🪨, paper 📜 or scissors ✂️.
main
branch againgit merge
to merge the my-turn
branch into your main
branchStarting situation
Rebasing
Merging
Rebasing
Rebasing into main
🙅
Rebasing into feature
💁
Any Questions?