Git Version Control: From Beginner to Advanced Guide
Git was created by Linus Torvalds in 2005 and is the world's most widely used distributed version control system. It tracks every version, every change, and every branch of your code.
Why Version Control?
- History — Every change is recorded; return to any point
- Collaboration — Multiple developers work on the same project
- Experimentation — Try safely in branches
- Backup — Remote repos (GitHub/GitLab) keep data safe
Core Workflow
Working Directory → Staging Area → Local Repo → Remote Repo
(git add) (git commit) (git push)
git add src/components/Header.tsx # Stage changes
git commit -m "feat: add mobile nav menu" # Commit
git push origin main # Push to remote
Branching & Merging
git checkout -b feature/login-page # Create + switch
git checkout main # Switch back
git merge feature/login-page # Merge branch
Commit Message Conventions
Conventional Commits format:
feat: New feature
fix: Bug fix
docs: Documentation
refactor: Code restructuring
test: Adding/fixing tests
chore: Maintenance
# ✅ Good
git commit -m "feat(auth): add Google OAuth integration"
# ❌ Bad
git commit -m "fix"
Workflow Strategies
GitHub Flow (Simple)
main + short-lived feature branches + PRs
Git Flow (Enterprise)
main + develop + feature/release/hotfix branches
Trunk-Based (Modern)
main + very short-lived branches (1-2 days max)
Essential Commands
| Command | Purpose |
|---------|---------|
| git status | Show changes |
| git log --oneline | Commit history |
| git diff | Show differences |
| git stash | Temporarily store changes |
| git reset --soft HEAD~1 | Undo last commit (keep changes) |
| git cherry-pick <hash> | Pick a single commit |
| git blame <file> | Show who wrote each line |
Conflict Resolution
When two branches modify the same line:
<<<<<<< HEAD
const title = "Hello World";
=======
const title = "Merhaba Dünya";
>>>>>>> feature/turkish
Manually choose the correct version, then git add . && git commit.
Conclusion
Git is the fundamental tool of modern software development. Start with add, commit, push, and gradually learn branching strategies and advanced commands.
Learn Git and development tools with interactive missions at LabLudus.