🌿 Git Mastery: The Complete Developer Guide This article is a comprehensive guide to Git, covering everything from initial setup and configuration to advanced branching strategies. It explains Git as a distributed version control system that tracks code changes, enables experimentation, and facilitates team collaboration, with practical commands for staging, committing, and managing branches. From your first commit to advanced branching strategies — everything you need to version control like a pro Every file you've ever accidentally deleted, every "final v3 REAL final.js" you've created — Git is the solution to all of that. It's a distributed version control system that tracks every change to your codebase, lets you experiment without fear, and enables teams of hundreds to collaborate without stepping on each other. Git isn't just a tool — it's the backbone of modern software development. GitHub, GitLab, Bitbucket — they're all built on top of it. Here's the mental model before we dive in: .git folder Verify your install: git --version git version 2.x.x Before your first commit, tell Git who you are. This info is embedded in every commit you make. git config --global user.name "Your Name" git config --global user.email "you@example.com" Set your default editor VS Code shown here git config --global core.editor "code --wait" Set default branch name to 'main' git config --global init.defaultBranch main Verify your config git config --list These settings live in ~/.gitconfig and apply to every repo on your machine. You can override them per-repo by dropping the --global flag. mkdir my-project && cd my-project git init Initialized empty Git repository in .git/ git clone https://github.com/user/repo.git Clone into a specific folder name git clone https://github.com/user/repo.git my-folder Clone only the latest snapshot faster for large repos git clone --depth 1 https://github.com/user/repo.git This is the heartbeat of Git. Everything else builds on it. Working Tree → Staging Area → Repository edit git add git commit git status What's changed? What's staged? git status -s Short format: M = modified, A = added, ? = untracked git add file.js Stage a specific file git add src/ Stage an entire directory git add . Stage everything in the current directory git add -p Interactive: stage changes chunk by chunk Pro tip: git add -p is one of Git's most underused features. It lets you review and selectively stage individual hunks of changes — perfect for keeping commits focused and atomic. git commit -m "feat: add user authentication" Stage all tracked files and commit in one step git commit -am "fix: correct typo in error message" Open your editor for a detailed commit message git commit Follow the Conventional Commits format: