In short
A commit is a saved snapshot of your project with a note saying what changed. Good commits make it easy to find bugs, undo mistakes and explain your work.
`git commit` saves a snapshot of your staged changes with a message — the fundamental unit of history in Git. A commit records a specific project state and points to its parent commit(s), which is what makes Git history navigable and branchable.

Think of it like this
Photos from a college trip
You don't click one photo for the whole trip. You click at each stop and caption it: 'Reached Manali', 'Snow point'. Commits are those photos for your code. Small, frequent, with captions that make sense later.
Watch it happen
The everyday commit loop
1/5You change files as usual. Git notices, but nothing is saved yet.
The big ideas
What you need to know
Stage what you want
git add picks which changes go into the next commit. You don't have to commit everything at once.
Every commit has an ID
Each commit gets a unique hash like a1b2c3d. You use it to look back, compare or undo.
Messages say why
Write a short line in the present tense, like 'Add contact form validation'. Not 'stuff' or 'changes'.
One idea per commit
Fixing a bug and redesigning the navbar? Two commits. It makes undoing one easy.
See it in code
Walk through the code
1git status2git diff # unstaged changes, line by line3 4git add index.html styles.css5git commit -m "Add hero section to homepage"6 7git log --oneline # short history8git show HEAD # what the last commit changed9 10# Forgot a file? Add it to the last commit (only if not pushed yet)11git add script.js12git commit --amend --no-edit1/4First look: which files changed, and exactly which lines changed inside them.
HEAD means 'the commit you're on right now'. Only amend commits you haven't pushed, because amending changes the commit's ID.
Save yourself the pain
Common mistakes
Oops
Making one giant commit at the end of the week called 'final'.
Do this instead
Commit each small, working step. Your history then reads like a story you can rewind.
Oops
Committing passwords or API keys in a .env file.
Do this instead
Add .env to .gitignore. If a key was already pushed, treat it as leaked and generate a new one.
Your mission
Write a clean history
Quick check
You edited three files but only two belong to the bug fix. What's the right move?
Go deeper
- 1Practice small, focused commits rather than one giant commit per day. Test it with at least one normal case and one edge case so you can explain the behavior confidently.
- 2Write commit messages in the imperative mood ('Add', not 'Added'). Validate your understanding by applying it in a small practical example.
- 3Learn `git commit --amend` to fix your most recent commit message.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.