What you will learn
- Explain what version control is and why every project needs it
- Initialise a repository and check its state with git status
- Stage and commit changes with git add and git commit
Version control records the history of a project, so you can see what changed, when and why, and return to an earlier version if something breaks. Git is the standard version control system. It runs on your own computer and stores the history in a hidden .git folder inside your project. Before your first commit, set your name and email with git config.
Open a terminal in your project folder and run git init to start a repository. git status shows which files are new or changed. Git uses a staging area: git add index.html marks a file to be included in the next snapshot, and git add . stages everything in the folder. This lets you choose exactly which changes go together.
git commit -m "Add product grid" saves the staged changes as a commit, a permanent snapshot with a message. git log lists past commits, and git diff shows changes you have not yet staged. Commit whenever you finish a small, working step. If you make a mistake later, you can compare against or restore an earlier commit rather than starting again from scratch.


