Loading
0x30Lesson 4 of 6

Work with branches and merges

Develop changes on a branch and bring finished work back together.

12 min 5-question quiz
By the end of this lesson you can
  • Create a branch, switch between branches and merge changes.

A branch is a movable name pointing to a commit. HEAD identifies the current checkout, usually through the current branch. Branches make it easy to develop separately; merging combines histories and may create a merge commit.

terminal · git
1git switch -c feature/profile
2# make and commit changes
3git add src/profile.js
4git commit -m "Add profile page"
5
6git switch main
7git merge feature/profile
Output
Switched to a new branch 'feature/profile'
[feature/profile 31ac901] Add profile page
Switched to branch 'main'
Updating ...
Fast-forward

A fast-forward merge moves the current branch pointer ahead when it has no unique commits. If both branches have new commits, Git combines the histories with a merge commit unless you choose another strategy.

Key takeaways

  • Branches are lightweight names pointing at commits.

  • git switch -c creates a branch and checks it out.

  • Merge brings a branch’s changes into the currently checked-out branch.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Did you like the lesson? 😆👍
Consider a donation to support our work: