git switch -c feature/add-greeting
echo "Welcome to PixelCraft!" > welcome.txt
git add . && git commit -m "Add welcome message"
git switch main # welcome.txt is GONE
ls # Not here
git switch feature/add-greeting
ls # It's back!
git switch main
git merge feature/add-greeting
ls # welcome.txt is now in main!
git branch -d feature/add-greeting # Clean up
Deliberately cause a conflict:
# Branch A
git switch -c branch-a
echo "Version A" > shared.txt
git add . && git commit -m "Branch A change"
# Branch B (from main)
git switch main
git switch -c branch-b
echo "Version B" > shared.txt
git add . && git commit -m "Branch B change"
# Merge both into main
git switch main
git merge branch-a # Works fine
git merge branch-b # CONFLICT!
Open the conflicted file. You'll see:
<<<<<<< HEAD
Version A
=======
Version B
>>>>>>> branch-b
Choose the correct content (or combine both). Remove the conflict markers. Save.
git add shared.txt
git commit -m "Resolve merge conflict between branch-a and branch-b"
Practice the full cycle three times with different branches:
# Repeat 3 times:
git switch -c feature/feature-name
# ... make changes, commit ...
git switch main
git merge feature/feature-name
git branch -d feature/feature-name
Then visualize the result:
git log --oneline --graph --all
Branching is state divergence.
Two versions of reality evolving independently. Merging is reconciliation — bringing them back together. This problem is universal.