Advanced Branch Management
Branch Rebase and Merge Strategies
gitGraph
commit
branch feature-x
checkout feature-x
commit
commit
checkout main
merge feature-x
Rebase vs Merge
Strategy |
Pros |
Cons |
Merge |
Preserves complete history |
Creates additional merge commits |
Rebase |
Linear, clean history |
Rewrites commit history |
Interactive Rebasing
## Interactive rebase of last 3 commits
$ git rebase -i HEAD~3
Branch Naming Conventions
## Recommended branch naming patterns
$ git checkout -b feature/user-authentication
$ git checkout -b bugfix/login-error
$ git checkout -b hotfix/security-patch
Managing Complex Workflows
Feature Branch Workflow
gitGraph
commit
branch feature-login
checkout feature-login
commit
commit
checkout main
merge feature-login
Advanced Git Commands
## Prune remote branches
$ git remote prune origin
## List branches with last commit date
$ git branch -vv
## Track remote branches
$ git branch -u origin/feature-branch
Stash Management
## Stash current changes
$ git stash save "Work in progress"
## List stashes
$ git stash list
## Apply most recent stash
$ git stash apply
LabEx Pro Tip
In LabEx's advanced Git training, explore complex branching scenarios and professional workflow techniques.
Best Practices
- Keep branches short-lived
- Use descriptive branch names
- Regularly synchronize with main branch
- Clean up merged and obsolete branches