In the first post, you learned the core commit loop. Now it is time to work in parallel. Branching is where Git starts to feel powerful, because you can experiment safely without destabilizing your main line.
Table of Contents
This post covers the core branching workflow and conflict recovery patterns.
Branch Fundamentals
Merge Mechanics
Context Switching
Series Navigation
Branch fundamentals
What a branch really is
A Git branch is a movable pointer to a commit. When you commit on that branch, the pointer moves forward. That means branches are lightweight and cheap to create.
Common branch roles in small teams:
main: stable and releasable historyfeature/<name>: isolated feature developmentfix/<name>: targeted bug fix work
Create and switch branches
View branches:
git branchCreate a feature branch and switch in one step:
git switch -c feature/add-health-endpointSwitch between existing branches:
git switch main
git switch feature/add-health-endpointIf your Git version is older, git checkout can do this too, but git switch is usually clearer.
Merge mechanics
When you merge a branch back into main, one of two patterns usually happens.
Fast-forward merge
If main has not moved since your branch was created, Git can move main forward directly with no new merge commit.
git switch main
git merge feature/add-health-endpointThis keeps history linear and simple.
Merge commit
If both branches have new commits, Git must create a merge commit to join both histories.
git switch main
git merge feature/add-health-endpointThe command looks the same, but the graph is different because Git preserves both lines of development.
Conflict resolution flow
A conflict means Git found overlapping edits and needs a human decision.
Conflict cycle:
- Run merge command.
- Git reports conflicted files.
- Open each file and resolve conflict markers.
- Stage resolved files.
- Complete merge commit.
Example conflict markers:
<<<<<<< HEAD
return "v1";
=======
return "v2";
>>>>>>> feature/api-versionAfter editing to the final desired content:
git add src/api/version.js
git commitIf you need to back out and retry:
git merge --abortContext switching
Using stash safely
git stash temporarily shelves local work when you need to switch tasks quickly.
git stash push -m "wip: validation for signup form"
git stash list
git switch mainRestore the latest stash and remove it from the stash stack:
git stash popRestore without removing:
git stash applyStash is useful, but do not let it become permanent storage. For meaningful progress, a regular commit on a feature branch is usually safer.
Tags vs branches
- Branches move forward as you add commits
- Tags point to a specific commit and stay fixed (often used for releases like
v1.3.0)
Understanding that difference helps avoid confusion when navigating project history later.
Practical habits that prevent branch pain
- Pull or fetch the latest
mainbefore starting a branch - Keep branches short-lived to reduce merge conflicts
- Use focused commits so conflicts are easier to reason about
- Merge often enough that divergence stays manageable
Next in this series
Next, we move to collaboration across machines and teammates: remotes, fetch/pull differences, upstream tracking, and pull request flow