What Is Git? Version Control Explained
Git is a distributed version control system created by Linus Torvalds in 2005. It tracks every change to a set of files, allowing multiple developers to collaborate, experiment in branches, and merge work without losing history. Nearly all modern software development — open source and commercial — uses Git.
Core Concepts: Commits, Branches, Merges
A commit is a snapshot of all tracked files at a point in time, identified by a SHA-1 hash. A branch is a lightweight pointer to a commit — creating a branch costs nothing. Merging combines divergent histories. A fast-forward merge simply advances the pointer; a three-way merge creates a new merge commit reconciling changes from both branches.
Staging Area and the Index
Git has three areas: the working tree (your files), the staging area (index), and the repository. `git add` moves changes to the staging area. `git commit` permanently records staged changes. This two-step process lets you craft clean, logical commits even when your working directory has many unrelated changes.
Rebase vs Merge
Merge preserves history exactly as it happened — useful for preserving the context of feature branches. Rebase replays commits on top of another branch, resulting in a linear history that's easier to read with `git log`. Avoid rebasing shared branches because it rewrites commit hashes, causing problems for others who have the original commits.