How to Commit Changes in Git (git commit)
git commit records the currently staged changes as a new snapshot in the repository's history, along with a message describing them.
Published September 27, 2026
git commit records the staged changes as a permanent snapshot in the repository history, with a message explaining why.
How it works
A commit has an author, timestamp, parent and a unique hash. Good messages have a short summary line and optional detail.
git commit -a stages tracked, modified files automatically (it does not add new files).
Try it
git commit -m "Fix login redirect"
[main 4f2a1b] Fix login redirect
1 file changed, 3 insertions(+)
Practical examples
Commit with a message
git commit -m "Add search endpoint"Stage tracked files and commit
git commit -am "Update docs"Multi-line message
git commit -m "Add cache" -m "Uses Redis with 5 minute TTL"Empty commit to trigger CI
git commit --allow-empty -m "Trigger build"Common mistakes
- Vague messages such as 'fix'.
- Committing unrelated changes together.
- Committing secrets or large generated files.
Key takeaways
- A commit is a snapshot with a message.
- Small focused commits.
- Write the why, not just the what.
FAQ
How long should a message be?
A subject under about 50 characters, then optional body.
Can I change it later?
Yes with git commit --amend for the last commit.