2024-09-07
Master Git with advanced branching strategies, conflict resolution, and team collaboration workflows.
Git is the backbone of modern software development. This guide covers advanced Git techniques, branching strategies, and collaboration workflows that professional teams use to manage complex projects effectively.
# Initialize and configure
git init
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
# Basic workflow
git add .
git commit -m "Descriptive commit message"
git push origin main
# Branching
git branch feature/new-feature
git checkout -b feature/new-feature
git merge feature/new-feature
# Stashing changes
git stash
git stash pop
git stash list
Branches:
• main - Production code
• develop - Integration branch
• feature/* - New features
• release/* - Release preparation
• hotfix/* - Emergency fixes
Best for: Projects with scheduled releases
Simple workflow:
1. Create branch from main
2. Add commits
3. Open pull request
4. Review and discuss
5. Merge to main
Best for: Continuous deployment
# Clean up commit history
git rebase -i HEAD~3
# Commands in interactive mode:
# pick - use commit
# reword - change commit message
# squash - combine with previous
# fixup - like squash but discard message
# drop - remove commit
# Apply specific commit to current branch
git cherry-pick abc123
# Cherry pick multiple commits
git cherry-pick abc123 def456
# Cherry pick a range
git cherry-pick abc123..xyz789
# Find the commit that introduced a bug
git bisect start
git bisect bad # Current commit is bad
git bisect good abc123 # Known good commit
# Git will checkout commits for testing
git bisect good # Mark as good
git bisect bad # Mark as bad
# When done
git bisect reset
Handling merge conflicts effectively:
# When conflict occurs
<<<<<<< HEAD
Your changes
=======
Their changes
>>>>>>> feature-branch
# Resolve conflict, then:
git add resolved-file.js
git commit
# Abort merge if needed
git merge --abort
Commit Messages
Write clear, descriptive commit messages. Use present tense and explain why, not just what.
Small, Atomic Commits
Make small, focused commits that address one specific change or feature.
Regular Pulls
Pull from upstream regularly to avoid large merge conflicts.
Published on 2024-09-07 • Category: DevOps
← Back to BlogFree online developer tools and utilities for encoding, formatting, generating, and analyzing data. No registration required - all tools work directly in your browser.
Built for developers, by developers. Privacy-focused and open source.
Free online tools for Base64 encoding, JSON formatting, URL encoding, hash generation, UUID creation, QR codes, JWT decoding, timestamp conversion, regex testing, and more.
© 2024 NarvikHub. All rights reserved.