git commit Save staged changes as a snapshot in history
Records everything in the staging area as a new commit, with your message, name and the time. A commit is a permanent checkpoint you can return to or share.
Synopsis
git commit [OPTION]...
Common options
| Option or form | What it does |
|---|---|
-m MESSAGE | Use this message instead of opening an editor |
-a | Automatically stage every tracked file that changed before committing |
--amend | Replace the last commit with a new one, to fix its message or add a forgotten file |
--no-edit | With --amend, keep the existing message |
-v | Show the diff in the editor while you write the message |
--allow-empty | Make a commit even when nothing changed |
Examples
git commit -m "Add contact form"
[main 3f2a9c1] Add contact form
2 files changed, 41 insertions(+)
git commit -am "Fix typo in header"
git commit --amend -m "Add contact form with validation"
git add forgot.txt && git commit --amend --no-edit
git commit
Notes
- Write messages in the imperative, such as "Fix login bug". The first line should be short, with detail after a blank line.
- -a does not include new files. Run git add first for those.
- Do not amend a commit you have already pushed to a shared branch, because it rewrites history others may have.
See also
Last reviewed 2026-10-09.