Skip to content
Git Basics: Staging Files and Making a Commit

Git Basics: Staging Files and Making a Commit

October 9, 2026

Git records project snapshots as commits. The staging area lets you choose what the next snapshot will contain. Start with one file so you can see each step.

Run these commands in Bash with Git 2.28 or newer installed. Each article starts in a fresh temporary repository; no remote account is needed.

git_practice=$(mktemp -d) || exit
cd "$git_practice" || exit
git init -q -b main
git config user.name 'Practice User'
git config user.email 'practice@example.invalid'
git config commit.gpgsign false

These settings apply only to this repository; signing is disabled for the exercise. Use your own identity in real projects. The temporary files remain after the exercise.

Create and stage a file

printf 'port=8080\n' > app.conf
git status --short
?? app.conf

?? means the file is untracked. Git sees it, but it has not been added to the staging area.

git add app.conf
git status --short
A  app.conf

The A in the first column means a new file is staged. git add copies the current file contents into the staging area. Editing the file afterward does not automatically update that staged copy.

Record the snapshot

git commit -q -m 'Add application port'
git log -1 --format=%s
Add application port

The message should describe the change clearly. The commit is stored locally; this command does not upload anything.

Check the repository again:

git status --short

No output means the working tree and staging area are clean, with no untracked files reported. Ignored files are not shown by default.

For your next change, repeat the same loop: edit, inspect, stage specific files, review, and commit. Explicit filenames make it easier to avoid accidentally including unrelated work or secrets. Never commit credentials just because the repository is currently private.

Reference

Git add manual

Acknowledgements

This post was created with assistance from AI.

Last updated on