# Git Add and Commit

> How a change goes from your files into Git's history. What the staging area is for, what git status tells you, and how .gitignore keeps files out.

**Course:** [Git and GitHub](https://learn.benibix.com/learn/development-version-control)  
**Time:** 12 min

**After this lesson you can:**

- Stage a change and commit it
- Read the output of git status
- Keep secret files out with .gitignore

## How a change becomes a commit

A commit is a saved version of your project, with a note saying what changed. Making one takes two commands. First, git add picks the changes to save. Then git commit saves them with a message. Each commit gets its own ID, like a205dfe, so you can find it again years later.

Your files live in three places in Git. The working directory is the folder you see and edit. The staging area is a waiting room for the changes you picked. The last commit is what Git has already saved. A change moves from one to the next, one command at a time.

Saving a file in your editor is not a commit. Git does not count it as part of the history yet. If you delete the file or change it again, the old version is gone for good. Only a commit puts a change into the history.

The staging area is there so you can split your work. Say you fixed a bug and changed a colour in the same hour. You can add the bug fix, commit it with its own message, then add the colour and commit again. Each commit then does one clear thing.

Git status tells you where every file sits right now. It lists files you changed but did not stage, files staged for the next commit, and new files Git is not tracking yet. It changes nothing, so you can run it as often as you like. Many people run it before every add.

The short form, git status --short, puts two letters in front of each file. The left letter is the staging area and the right one is your folder. A means added, and M means changed. Two question marks mean untracked: a new file Git has never saved.

Some files should never be saved at all, like passwords, keys and big folders a tool can rebuild. A file called .gitignore lists them, one name or pattern per line. Files that match disappear from git status and cannot be added by mistake. It only works on files Git is not tracking yet.

The most common slip is git add with a dot, which stages every change in the folder. That is how a password file ends up in a shared repo. Run git status first, read the list, then add files by name. Once a secret is shared, change the secret, because deleting the file later does not erase it from the history.

```console
$ git status --short
?? index.html
?? style.css
$ git add index.html
$ git status --short
A  index.html
?? style.css
$ git commit -m "Add home page"
[main (root-commit) a205dfe] Add home page
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
```
Two new files. One is staged and committed. style.css stays untracked, because it was never added.

```gitignore
# .gitignore
node_modules/
.env
*.log
```
This leaves out the folder of downloaded packages and the file of secrets. It also leaves out every file that ends in .log.

![Three columns from left to right: working directory, staging area and last commit, with arrows labelled add and commit between them. A file called style.css sits in the working directory, marked changed but not staged. A file called notes.txt sits there too, marked new and untracked. A file called index.html sits in the staging area, marked ready to commit.](https://learn.benibix.com/diagrams/dev3-git-status.svg)

### Example: Jack splits a messy afternoon

Jack changes 3 files in one afternoon. Two of them fix a broken login form, and one makes the page header green.

He adds the two login files and commits them as Fix the login form. Then he adds the third as Make the header green. When the team dislikes the green, that one commit can go without touching the fix.

**Words in this lesson:** [Working Directory](https://learn.benibix.com/term/development/working-directory), [Staging Area](https://learn.benibix.com/term/development/staging-area), [Commit](https://learn.benibix.com/term/development/commit), [Git Status](https://learn.benibix.com/term/development/git-status), [.gitignore](https://learn.benibix.com/term/development/gitignore)

**Question:** Is a file I saved in my editor already safe in Git?

**Answer:** No, it joins the history only after you add and commit it. Saving in the editor only changes the file in your folder. Git adds it to the history when you stage it with git add and save it with git commit.

---

Source: https://learn.benibix.com/learn/development-version-control/git-add-and-commit
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
