Here's the problem. You and your colleague both need to write tests. You're working on Login tests, they're working on Cart tests. If you both commit to the same branch — it's chaos. Your half-written code breaks their tests, their changes break yours.
Branches solve this. Think of it like making a photocopy of your test framework. You experiment on your copy. Your colleague experiments on theirs. When you're done and everything passes, you merge your copy back into the original. Nobody steps on anyone's toes.
# See which branch you're on right now
git branch
# * main ← the * means you're here
# Create a new branch
git branch feature/login-tests
# Switch to that branch
git checkout feature/login-tests
# Switched to branch 'feature/login-tests'
# Shortcut: create AND switch in one command (use this)
git checkout -b feature/cart-tests
# List all branches
git branch
# main
# feature/login-tests
# * feature/cart-tests ← you're here now
# Switch back to main
git checkout main
# Delete a merged branch (cleanup after merge)
git branch -d feature/cart-tests
# Force-delete an unmerged branch (careful — loses work)
git branch -D feature/cart-tests# Monday morning. You need to write login tests.
# Step 1: Start from latest main
git checkout main
git pull origin main
# Step 2: Create your branch
git checkout -b feature/login-tests
# Step 3: Write your tests, commit often
# ... write LoginTest.java ...
git add LoginTest.java
git commit -m "Add login test for valid credentials"
# ... write LoginPage.java ...
git add LoginPage.java
git commit -m "Add LoginPage page object with locators"
# Step 4: Done for the day? Push to GitHub
git push origin feature/login-tests
# Step 5: Create a Pull Request on GitHub
# (We'll cover this in the GitHub lesson)Never commit directly to main. Always create a branch first. This is rule #1 in every professional team. If you commit directly to main and break something — the entire team is affected.
Naming convention: feature/login-tests, bugfix/fix-cart-locator, refactor/page-object-cleanup. Use lowercase, hyphens, descriptive names. Your team lead will thank you.
Q: What branching strategy does your team follow?
A: We follow the Feature Branch workflow. The main branch is always stable — all tests pass there. Each tester creates a feature branch for their work (like feature/login-tests or bugfix/fix-cart-locator). When done, they push the branch to GitHub and create a Pull Request. The team reviews the PR, and once approved, it gets merged into main. We never commit directly to main.
Key Point: Always create a branch before starting work. main stays stable, you experiment on your branch.