1. Branch Management 💡
- Feature Branch Workflow: Create isolated branches for new features using
git branch <branch_name>
- Rebase vs Merge: Use
git rebase
to linearize history orgit merge
for preserving merge commits - Cherry-Picking: Apply specific commits from one branch to another with
git cherry-pick <commit_hash>
2. Undo Changes ⚠️
- Soft Reset:
git reset --soft <commit>
keeps changes in staging area - Mixed Reset:
git reset --mixed <commit>
(default) unstage changes but keeps them in working directory - Hard Reset:
git reset --hard <commit>
discards all local changes
3. Remote Repository Operations 🌐
- Push with Force:
git push --force
overrides remote history (use cautiously) - Fetch vs Pull:
git fetch
retrieves changes without merging,git pull
combines both - Stashing Changes: Temporarily save work with
git stash
4. Git Hooks ⚙️
- Pre-commit: Validate code before committing
- Post-checkout: Automate tasks after switching branches
- Custom Scripts: Place scripts in
.git/hooks/
for automation
5. Advanced Workflows 📈
- Git Bisect: Debugging with
git bisect start
andgit bisect good/bad
- Submodules: Manage external repositories with
git submodule add <url>
- Sparse Checkout: Clone only specific directories using
git sparse-checkout set
For more details on Git fundamentals, visit our Git Basics Tutorial.