A feature branch workflow where you develop a new Claude-powered feature on a branch, then merge it back to main cleanly — the exact workflow used at every tech company.
Understanding Branches
A branch is a parallel copy of your codebase. You make changes on the branch without touching main. When the feature works, you merge it in. If it fails, you delete the branch — main is untouched.
# See all branches
git branch
# * main
# Create and switch to a new branch
git checkout -b feature/add-claude-api
# Switched to a new branch 'feature/add-claude-api'
# Or using the modern syntax
git switch -c feature/add-claude-api
# See branches (asterisk = current)
git branch
# * feature/add-claude-api
# mainDevelop on a Branch
Add your code on the branch. Commits here don't affect main. This is how teams work on multiple features simultaneously.
import anthropic
import os
from dotenv import load_dotenv
load_dotenv()
client = anthropic.Anthropic()
def summarize(text: str) -> str:
# Summarize text using Claude
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=256,
messages=[{"role": "user", "content": f"Summarize in 2 sentences: {text}"}]
)
return response.content[0].text# Stage and commit on the branch
git add main.py
git commit -m "Add Claude summarization function"
# Push branch to GitHub
git push -u origin feature/add-claude-apiMerge the Branch Back to Main
When the feature is done and tested, merge it to main. There are two ways: git merge locally, or a Pull Request on GitHub (the professional way).
# Switch back to main
git checkout main
# Merge the feature branch
git merge feature/add-claude-api
# Updating a1b2c3d..d4e5f6a
# Fast-forward
# main.py | 14 ++++++++++++++
# Delete the branch (it's merged, no longer needed)
git branch -d feature/add-claude-api
# Push the updated main
git pushFast-forward merge: Happens when main hasn't changed since you branched. Git just moves the pointer forward. No merge commit needed.
Resolve Merge Conflicts
Conflicts happen when two branches change the same line. Git marks them clearly so you can choose which version to keep.
<<<<<<< HEAD (your current branch)
model="claude-opus-4-5"
=======
model="claude-haiku-20240307"
>>>>>>> feature/use-haikuEdit the file to keep what you want (delete the conflict markers and both versions, keep only your chosen line). Then:
# After resolving conflicts in your editor
git add main.py
git commit -m "Merge feature/use-haiku — keep opus for quality"What You Learned Today
- Created feature branches with meaningful names
- Committed code on a branch without affecting main
- Merged a branch back to main using fast-forward merge
- Resolved a merge conflict by editing conflict markers
Go Further on Your Own
- Create a branch called fix/improve-prompt, change the prompt in your summarize function, and merge it
- Practice the Pull Request workflow on GitHub instead of local merge
- Create a git alias: git config --global alias.lg 'log --oneline --graph --all'
Nice work. Keep going.
Day 3 is ready when you are.
Continue to Day 3Want live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.