Master Git Completely
From your first repository to advanced team workflows. The definitive guide for developers who want to version control like pros.
Start Learning Now📚 Choose Your Path
Jump to any section or scroll through the complete guide
Installation
Setup & Configuration
Fundamentals
Core Concepts
Branching
Parallel Development
Merging
Combining Work
Remote Repos
Collaboration
Advanced
Power User Tips
Installation & Setup
BeginnerLet’s get Git installed and configured properly. This foundation prevents 90% of beginner frustrations.
Windows
Download from git-scm.com or use winget install Git.Git
macOS
Install Xcode CLI tools or brew install git via Homebrew
Linux
Ubuntu/Debian: sudo apt-get install git
# Identity (required for every commit) git config --global user.name "Your Name" git config --global user.email "your.email@example.com" # Modern default branch naming git config --global init.defaultBranch main # Better diffs and colors git config --global color.ui auto git config --global core.pager cat
git config --list to verify settings. Use --local instead of --global for project-specific settings.
Git Fundamentals
BeginnerGit has three areas where your files live. Understanding this workflow is crucial:
Working Directory
Your local files
Staging Area
Pre-commit snapshot
Repository
Permanent history
git status # Check current state git add filename # Stage specific file git add . # Stage all changes git commit -m "msg" # Save with message git log --oneline # View compact history git diff # See unstaged changes
git add before git commit. Always check git status to see what’s staged!
Branching Strategy
IntermediateBranches let you work on features, fixes, and experiments in isolation without breaking the main codebase.
Visual Branch Structure
git branch # List branches (* = current) git branch new-name # Create branch git checkout new-name # Switch to branch (old) git switch new-name # Switch to branch (new) git switch -c new-name # Create and switch git branch -d name # Delete merged branch git branch -D name # Force delete
Git Flow
Complex but structured: main, develop, feature, release, and hotfix branches. Best for scheduled releases.
GitHub Flow
Simple: main + feature branches. Create Pull Request, review, merge. Perfect for continuous deployment.
Trunk Based
Short-lived branches (1-2 days max). Requires feature flags. Fastest for high-performing teams.
Merging & Rebasing
IntermediateCombining work requires strategy. Choose the right approach for clean, understandable history.
# Standard merge (preserves history, creates merge commit) git switch main git merge feature/login # Squash merge (combines all feature commits into one) git merge --squash feature/login git commit -m "Add login feature" # Fast-forward (linear history, no merge commit) git merge --ff-only feature/login
# Move feature branch to tip of main git switch feature/login git rebase main # Interactive rebase (edit/squash/reorder commits) git rebase -i HEAD~3 # If conflicts occur during rebase # 1. Fix conflicts, 2. git add ., 3. git rebase --continue git rebase --abort # Cancel rebase
Remote Repositories
IntermediateConnect your local work to the world. Push, pull, and collaborate with teams anywhere.
git remote -v # View remotes git fetch origin # Download changes (no merge) git pull origin main # Fetch + merge git push -u origin feature # Push and track branch git push origin --delete feature # Remove remote branch git clone https://... # Copy repository
fetch to preview changes before merging. pull immediately merges, which might surprise you with conflicts!
Advanced Techniques
AdvancedEmergency recovery, debugging, and power-user workflows. These tools separate experts from beginners.
Undo Anything
git reset, revert, restore, and reflog for every undo scenario
Bisect Debugging
Binary search through history to find which commit introduced a bug
Stashing
Save work-in-progress without committing messy code
Tagging
Mark release points with semantic versioning (v1.0.0)
# Undo last commit, keep changes staged git reset --soft HEAD~1 # Undo last commit, unstage changes git reset HEAD~1 # Undo last commit, discard all changes (DANGER) git reset --hard HEAD~1 # Create new commit that reverses specific commit git revert a1b2c3d # THE LIFESAVER: View all recent HEAD positions git reflog git checkout -b recovery HEAD@{2}
git stash push -m "WIP: login form" # Save with message git stash list # View saved stashes git stash pop # Apply and remove git stash apply stash@{1} # Apply specific stash git stash branch new-branch # Create branch from stash
git reflog!
Complete Cheat Sheet
Reference[alias]
co = checkout
br = branch
ci = commit
st = status
lg = log --oneline --graph --decorate --all
last = log -1 HEAD
unstage = reset HEAD --
undo = reset --soft HEAD~1
🎉 You’ve Mastered Git!
From initialization to advanced recovery techniques, you now have the skills to version control like a professional.
