Branches are where the real power of Git shines. They let you experiment without breaking your main codebase.
Creating a Branch
git checkout -b feature/new-feature
This creates a new branch and switches to it immediately.
Working on Your Branch
Make changes, commit them as usual:
git add .
git commit -m "Add new feature"
Your changes are isolated from the main branch until you decide to merge.
Merging Back
When your feature is ready, merge it back:
git checkout main
git merge feature/new-feature
Handling Conflicts
Sometimes Git can’t auto-merge. When that happens:
- Open the conflicting files
- Look for
<<<<<<<markers - Resolve the conflicts manually
- Stage and commit the resolution
In the final part of this series, we’ll cover working with remote repositories.