Git basics
Git is a time machine for your files. It records small snapshots called commits, lets you experiment on branches, and helps you share work with a remote repository.
What you will learn
- The difference between a working tree, staging area, and commit
- How to save one logical change
- How branches help you experiment safely
- Why reviewing changes before committing matters
Important terms
- Repository
- The project folder and its Git history.
- Working tree
- The files you are currently editing.
- Staging area
- The changes selected for the next commit.
- Commit
- A saved checkpoint with a message.
- Branch
- A separate line of work that can later be merged.
Save one file
git status
git add index.html
git commit -m "Update the home page"
git log --oneline
First inspect the changes, then choose what belongs in the next snapshot with git add. Finally, save that selection with git commit.
Result: after the commit, git status no longer shows those changes as uncommitted.
Experiment on a branch
git switch -c feature/header
# edit files, then review and commit
git status
git add .
git commit -m "Add a header"
git switch main
git merge feature/header
Common points to remember
- A commit is not the same as a backup of every untracked file.
- Use clear, small commits so the history explains what changed.
- Review
git diffbefore staging and committing. - Be careful with commands that rewrite shared history.