Git
Git is a distributed version control system that tracks changes to files over time, allowing multiple developers to collaborate on code, review history, create parallel branches, and merge changes — all with the ability to revert to any previous state.
Explanation
Git's core model: a repository is a collection of snapshots (commits). Each commit captures the state of all tracked files at a point in time, along with a pointer to its parent commit(s) and metadata (author, message, timestamp). This forms a directed acyclic graph (DAG) of commits. The HEAD pointer marks the current commit; branches are named pointers to specific commits. Key commands: git init / git clone (create/copy a repo), git add (stage changes for the next commit), git commit (create a snapshot of staged changes), git push / git pull (sync with a remote repository), git branch / git checkout -b (create/switch branches), git merge (combine branches), git rebase (replay commits on a new base — creates linear history), git log / git diff (inspect history/changes), and git stash (temporarily shelf uncommitted changes). Merge vs rebase: git merge combines two branches, creating a merge commit with two parents (preserves full history). git rebase takes your commits and replays them on top of another branch (creates clean linear history but rewrites commits — never rebase shared/public branches). Both integrate changes; the choice is about history aesthetics and team conventions. The staging area (index) is a Git-specific concept: git add moves changes to staging, and git commit creates a commit from staged changes. This two-step process lets you selectively commit some changes while leaving others unstaged, enabling clean, focused commits.
Code Example
bash# Common Git workflow
# One-time setup
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
# Daily workflow
git status # see what's changed
git diff # see exact changes
git add -p # interactively stage changes (review before committing)
git commit -m "feat: add user authentication"
# Feature branch workflow
git checkout -b feature/user-auth # create and switch to new branch
# ... make changes ...
git add .
git commit -m "feat: add JWT authentication middleware"
git push origin feature/user-auth
# Merge via pull request (GitHub/GitLab), or locally:
git checkout main
git merge feature/user-auth --no-ff # --no-ff preserves branch history
# Undo last commit (keep changes staged)
git reset --soft HEAD~1
# Undo last commit (discard changes — dangerous!)
git reset --hard HEAD~1
# View history
git log --oneline --graph --all # visual branch/merge history
Why It Matters for Engineers
Git is non-negotiable for software engineering. Every professional codebase uses Git or a similar VCS. Without Git, you have no safety net for experiments, no way to collaborate without overwriting each other's work, and no audit trail for debugging. "It worked yesterday" becomes "when was yesterday's working state committed?" — a question Git can answer. Understanding Git also enables code review workflows (pull requests on GitHub/GitLab), CI/CD pipelines (triggered by git push), GitOps (infrastructure managed via Git), and the branching strategies (Gitflow, trunk-based development) that teams use to coordinate feature development.