Branching & Contribution
Simple and practical branching strategy that matches how we actually work in projects.
Branch Naming Convention
Section titled “Branch Naming Convention”Follow this pattern: yourname/type/feature-description
Examples:
Section titled “Examples:”# Feature branchesjohn/feature/user-authenticationsarah/feature/payment-integration
# Bug fixesmike/fix/login-erroralice/fix/header-styling
# Refactoringbob/refactor/api-clientmary/refactor/user-service
# Other typesalex/docs/setup-guidelisa/chore/update-dependencies
Basic Workflow
Section titled “Basic Workflow”1. Create and Switch to Branch
Section titled “1. Create and Switch to Branch”# Create new branch from maingit checkout maingit pull origin maingit checkout -b yourname/feature/user-dashboard
2. Work on Your Feature
Section titled “2. Work on Your Feature”# Make changesgit add .git commit -m "Add user dashboard component"
# Push to GitHubgit push origin yourname/feature/user-dashboard
3. Create Pull Request
Section titled “3. Create Pull Request”- Go to GitHub
- Click “Compare & pull request”
- Use the PR template
- Link to related issue:
Closes #123
- Request review
4. After PR is Merged
Section titled “4. After PR is Merged”# Switch back to main and clean upgit checkout maingit pull origin maingit branch -d yourname/feature/user-dashboard
Working with Issues
Section titled “Working with Issues”Issue to Branch Flow:
Section titled “Issue to Branch Flow:”- Pick an issue from the project
- Assign yourself to the issue
- Create branch using issue description
- Work on the feature
- Create PR that closes the issue
Example:
Section titled “Example:”- Issue #45: “Add dark mode toggle”
- Branch:
yourname/feature/dark-mode-toggle
- PR title: “Add dark mode toggle (Closes #45)“
Collaboration Tips
Section titled “Collaboration Tips”Before Starting Work:
Section titled “Before Starting Work:”# Always start from latest maingit checkout maingit pull origin maingit checkout -b yourname/feature/new-feature
Keep Branch Updated:
Section titled “Keep Branch Updated:”# If main has new changes while you workgit checkout maingit pull origin maingit checkout yourname/feature/new-featuregit merge main
Small, Focused Changes:
Section titled “Small, Focused Changes:”- One feature per branch
- Keep PRs small and reviewable
- Don’t mix different types of changes
Conflict Resolution & Avoidance
Section titled “Conflict Resolution & Avoidance”Preventing Conflicts
Section titled “Preventing Conflicts”Best practices to avoid conflicts:
- Pull from main frequently (at least daily)
- Keep branches short-lived (merge within 2-3 days)
- Communicate with team about file changes
- Use clear commit messages
# Daily routine to avoid conflictsgit checkout maingit pull origin maingit checkout yourname/feature/current-workgit merge main # or git rebase main for cleaner history
When Conflicts Happen
Section titled “When Conflicts Happen”Step-by-step conflict resolution:
- Fetch latest changes:
git checkout maingit pull origin maingit checkout yourname/feature/conflicted-branchgit merge main
- Git will show conflict markers:
// Example conflict in a file<<<<<<< HEADconst apiUrl = 'https://api.staging.example.com';=======const apiUrl = 'https://api.production.example.com';>>>>>>> main
- Resolve conflicts manually:
// Choose the correct version or combine bothconst apiUrl = process.env.NODE_ENV === 'production' ? 'https://api.production.example.com' : 'https://api.staging.example.com';
- Complete the merge:
git add .git commit -m "Resolve merge conflict in api configuration"git push origin yourname/feature/conflicted-branch
Common Conflict Scenarios
Section titled “Common Conflict Scenarios”# When multiple people add dependencies# Always accept both changes and remove duplicates manuallygit checkout --theirs package.jsonnpm install # or yarn installgit add package.json package-lock.json
# When editing same lines in a file# 1. Look at both changes# 2. Decide which is correct or combine them# 3. Remove conflict markers (<<<, ===, >>>)# 4. Test the changes work
# When file is renamed/moved in different branches# 1. Choose the correct location# 2. Make sure imports are updated# 3. Delete the duplicate file if existsgit add .git rm old-file-name.js # if needed
If You’re Stuck
Section titled “If You’re Stuck”When conflicts seem overwhelming:
- Reset and try again:
git merge --abort # Cancel the mergegit checkout maingit pull origin main# Start over with fresh approach
- Ask for help:
- Share your screen with a teammate
- Use GitHub’s conflict resolution interface
- Create a new branch and cherry-pick specific commits
- Use VS Code merge tools:
- Install Git Graph extension
- Use built-in merge conflict resolver
- Visual diff makes conflicts easier to understand
Common Scenarios
Section titled “Common Scenarios”Working on Same Feature:
Section titled “Working on Same Feature:”If multiple people work on one big feature:
- Create feature branch:
feature/payment-system
- Everyone branches from it:
john/feature/payment-ui
,sarah/feature/payment-api
- Merge individual branches to feature branch
- Merge feature branch to main when complete
Hotfix:
Section titled “Hotfix:”For urgent production fixes:
# Create hotfix branch from maingit checkout maingit pull origin maingit checkout -b yourname/hotfix/critical-security-fix
# After fix, create PR to main immediately
Review Process
Section titled “Review Process”For PR Authors:
Section titled “For PR Authors:”- Use descriptive PR titles
- Fill out the PR template completely
- Link related issues
- Respond to review feedback quickly
For Reviewers:
Section titled “For Reviewers:”- Check that code works
- Verify it follows project guidelines
- Test the changes if possible
- Be constructive in feedback