← Lessons/Branching & Merging
← Branching & Merging

Merge back into main

Learn

Merge it back

When the work is ready, switch to the branch you want to bring it into, and merge:

git switch main
git merge hotfix

Here main hasn't moved since the branch was made, so Git simply moves main forward to include the branch's commits (a fast-forward). When both branches have moved on, Git creates a merge commit instead. Either way, git log on main now includes the work.

Switch back to main and git merge feature to fold the feature work in. Run git log --oneline — main now contains the Add feature commit.

Interview prep

Comfort with branch → commit → merge is the baseline expectation for collaborating on a team.

Why work on a branch instead of committing straight to main?

A branch isolates in-progress work so main stays stable and releasable. You can experiment, commit incrementally, and have the work reviewed (a pull request) before merging — and if it doesn't pan out, you just delete the branch. It also lets several people work in parallel without stepping on each other.

sandbox@opspath: ~
OpsPath sandbox · Debian GNU/Linux 12 · GNU bash 5.2
Your session carries over: files, commits, branches and cd all stick.
Press restart (top right) to go back to this mini lesson's starting point.
Type a command and press Enter. ↑/↓ history · Ctrl+L clear · Ctrl+C cancel line
# ── Step 3 · Merge back into main ──
# Sign in to run commands — it's free.