5.2 KiB
5.2 KiB
Git Branch Setup Guide
Creating Branches: akhib and dundu
Quick Commands
# Create and push akhib branch
git checkout -b akhib
git push -u origin akhib
# Create and push dundu branch
git checkout -b dundu
git push -u origin dundu
# Go back to main branch
git checkout main
Detailed Step-by-Step
Step 1: Check Your Current Branch
git branch
This shows which branch you're currently on (marked with *).
Step 2: Create akhib Branch
# Create new branch from current position
git checkout -b akhib
# Verify you're on the new branch
git branch
# Push to remote and set upstream
git push -u origin akhib
Step 3: Create dundu Branch
# Go back to main first
git checkout main
# Create new branch from main
git checkout -b dundu
# Push to remote and set upstream
git push -u origin dundu
Step 4: Verify All Branches Exist
# List local branches
git branch
# List all branches (local + remote)
git branch -a
You should see:
* main
akhib
dundu
remotes/origin/akhib
remotes/origin/dundu
remotes/origin/main
Branch Workflow for Team
For Developer Working on akhib Branch
# Switch to akhib branch
git checkout akhib
# Make sure it's up to date
git pull origin akhib
# Make changes, then commit
git add .
git commit -m "Your commit message"
# Push changes
git push origin akhib
For Developer Working on dundu Branch
# Switch to dundu branch
git checkout dundu
# Make sure it's up to date
git pull origin dundu
# Make changes, then commit
git add .
git commit -m "Your commit message"
# Push changes
git push origin dundu
Merging Changes
Merge akhib into main
# Switch to main
git checkout main
# Pull latest changes
git pull origin main
# Merge akhib branch
git merge akhib
# Push merged changes
git push origin main
Merge dundu into main
# Switch to main
git checkout main
# Pull latest changes
git pull origin main
# Merge dundu branch
git merge dundu
# Push merged changes
git push origin main
Branch Protection (Recommended)
After creating branches, consider setting up branch protection rules on GitHub/GitLab:
- Protect main branch - Require pull requests
- Require reviews - At least 1 approval before merging
- Require tests - Ensure CI/CD passes
Common Branch Commands
# List all branches
git branch -a
# Switch branches
git checkout branch-name
# Create new branch
git checkout -b new-branch-name
# Delete local branch
git branch -d branch-name
# Delete remote branch
git push origin --delete branch-name
# Rename current branch
git branch -m new-name
# See which branch you're on
git branch
# Update all branches from remote
git fetch --all
# See commits difference between branches
git log main..akhib
Branch Strategy Recommendation
Main Branch
- Purpose: Production-ready code
- Protection: Require pull requests
- Who commits: No direct commits (only via PR)
akhib Branch
- Purpose: Akhib's development work
- Protection: Optional
- Who commits: Akhib (and approved team members)
dundu Branch
- Purpose: Dundu's development work
- Protection: Optional
- Who commits: Dundu (and approved team members)
Workflow Example
graph LR
A[main] --> B[akhib branch]
A --> C[dundu branch]
B --> D[Pull Request to main]
C --> E[Pull Request to main]
D --> A
E --> A
Recommended Flow:
- Developer creates feature on their branch (akhib/dundu)
- Commits and pushes regularly
- When ready, creates Pull Request to main
- Team reviews the PR
- After approval, merge to main
- Delete feature branch (optional) or keep for next feature
Syncing Branches
Keep akhib up to date with main
git checkout akhib
git pull origin main
git push origin akhib
Keep dundu up to date with main
git checkout dundu
git pull origin main
git push origin dundu
Troubleshooting
Error: "branch already exists"
# If branch exists locally, just switch to it
git checkout akhib
# If you want to recreate it
git branch -d akhib
git checkout -b akhib
Error: "failed to push some refs"
# Pull first, then push
git pull origin akhib
git push origin akhib
Merge Conflicts
# When merge conflict occurs
git status # See conflicted files
# Edit conflicted files manually
# Look for <<<<<<, ======, >>>>>> markers
# After fixing conflicts
git add .
git commit -m "Resolve merge conflicts"
git push
Quick Reference
| Command | Description |
|---|---|
git checkout -b akhib |
Create akhib branch |
git push -u origin akhib |
Push and track akhib |
git checkout akhib |
Switch to akhib |
git branch |
List local branches |
git branch -a |
List all branches |
git merge akhib |
Merge akhib into current |
git pull origin akhib |
Update akhib from remote |
Setting Up Branch Protection (GitHub)
- Go to: Settings → Branches → Add rule
- Branch name pattern:
main - Enable:
- ✅ Require pull request reviews before merging
- ✅ Require status checks to pass
- ✅ Require branches to be up to date
- Save changes
Now your branches are ready for team collaboration! 🎉