Branch Management
Branch Lifecycle Management
Creating Branches
## Create a new branch
git branch feature/new-module
## Create and switch to a new branch
git checkout -b bugfix/critical-issue
Merging Strategies
Fast-Forward Merge
## Switch to main branch
git checkout main
## Merge feature branch
git merge feature/new-module
Merge Workflow Visualization
gitGraph
commit
branch feature
checkout feature
commit
commit
checkout main
merge feature
Branch Deletion and Cleanup
## Delete a local branch
git branch -d feature/completed-feature
## Force delete an unmerged branch
git branch -D experimental-branch
## Prune remote-tracking branches
git remote prune origin
Branch Management Best Practices
Practice |
Description |
Command |
Regular Cleanup |
Remove merged branches |
git branch -d |
Remote Sync |
Update remote branches |
git fetch --prune |
Branch Protection |
Prevent direct commits |
Repository settings |
Advanced Branch Operations
Rebasing
## Rebase feature branch onto main
git checkout feature/update
git rebase main
Branch Tracking
## Set up branch tracking
git branch -u origin/feature/new-module
Conflict Resolution
## Resolve merge conflicts
git merge feature/conflicting-branch
## Manually edit conflicting files
git add .
git commit
Branch Protection Strategies
- Use protected branches
- Require pull request reviews
- Implement status checks
- Restrict direct commits
Workflow Scenarios
stateDiagram-v2
[*] --> Development
Development --> Feature
Feature --> Testing
Testing --> Staging
Staging --> Production
Production --> [*]
At LabEx, we recommend a systematic approach to branch management that ensures code quality and team collaboration.