Courses Curriculum Cities Blog Enroll Now
Git & GitHub for AI Projects · Day 2 of 5 ~35 minutes

Day 2: Branching: Work Without Breaking Things

Use branches to experiment safely, merge changes cleanly, and keep your main branch always deployable.

1
Day 1
2
Day 2
3
Day 3
4
Day 4
5
Day 5
What You'll Build

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.

1
Section 1 · 8 min

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.

bashterminal
# 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
#   main
2
Section 2 · 10 min

Develop on a Branch

Add your code on the branch. Commits here don't affect main. This is how teams work on multiple features simultaneously.

pythonmain.py
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
bashterminal
# 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-api
3
Section 3 · 9 min

Merge 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).

bashterminal — local merge
# 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 push

Fast-forward merge: Happens when main hasn't changed since you branched. Git just moves the pointer forward. No merge commit needed.

4
Section 4 · 8 min

Resolve Merge Conflicts

Conflicts happen when two branches change the same line. Git marks them clearly so you can choose which version to keep.

textconflict markers in main.py
<<<<<<< HEAD (your current branch)
model="claude-opus-4-5"
=======
model="claude-haiku-20240307"
>>>>>>> feature/use-haiku

Edit the file to keep what you want (delete the conflict markers and both versions, keep only your chosen line). Then:

bashterminal
# 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
Your Challenge

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'
Day 2 Complete

Nice work. Keep going.

Day 3 is ready when you are.

Continue to Day 3
Course Progress
40%

Want live instruction and hands-on projects? Join the AI bootcamp — 3 days, 5 cities.

Finished this lesson?