What is git checkout?
Answer
git checkout is one of Git's most versatile commands with multiple purposes. Main uses: (1) Switch branches: git checkout main — move to main branch; Git updates the working directory to match; (2) Create and switch: git checkout -b feature-x — create and immediately switch to a new branch; (3) Checkout a specific commit (detached HEAD): git checkout abc1234 — view the repo at that point in history; (4) Restore files: git checkout -- file.txt (legacy) or git restore file.txt (modern) — discard working directory changes to a file, reverting to the staged or last-committed version. Irreversible — discards unsaved changes! (5) Checkout a file from another branch: git checkout feature -- src/utils.js — bring a specific file from another branch into current working directory. Git 2.23+ split checkout's concerns into: git switch (for changing branches) and git restore (for restoring files) — clearer semantics. git checkout still works for backward compatibility but the newer commands are recommended for clarity.