The Staging Area & Commits
The Three Areas of Git
This is the concept beginners trip on. Files move through three places:
Working Directory ──git add──▶ Staging Area ──git commit──▶ Repository
(your edits) (what's next) (history)
Analogy: The staging area is a packing box.git addputs specific items in the box;git commitseals and labels it. You choose exactly what goes in each snapshot - you don't have to commit everything at once.
| Command | Does |
|---|---|
git add file.txt | Stage one file |
git add . | Stage everything changed |
git commit -m "message" | Snapshot the staged files |
git commit -am "msg" | Stage tracked files and commit in one step |
$ echo 'hello' > readme.md
$ git add readme.md
$ git commit -m "Add readme"
[main (root-commit) a1b2c3d] Add readme
1 file changed, 1 insertion(+)
Tip: Write commit messages in the imperative: "Add login page", not "Added login page". It reads like a command the commit performs - the Git convention.