By admin , 29 April 2026

Synopsis

git commit [-m <msg>] [-a] [--amend] [--no-verify] [-S]

Description

The git commit command takes everything currently in the staging area and creates a new commit object in the repository. A commit is an immutable snapshot containing a tree (the file contents), parent pointer(s), author and committer metadata, and a message. Commits are the unit of history in Git: branches are pointers to commits, merges produce commits with multiple parents, and tags label specific commits.

A good commit message has a short subject line (under 50 characters), a blank line, and an optional body explaining the why. Many teams use conventional commits or other prefix systems. The --amend option modifies the most recent commit, useful for fixing typos in the message or forgetting to stage a file — but never amend a commit that has already been pushed and shared.

In day-to-day use, git commit integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git commit --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git commit interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git commit's side effects helps avoid all three.

Common Options

OptionDescription
-m <msg>Use the given message instead of opening an editor.
-a, --allAutomatically stage modifications and deletions to tracked files before committing.
--amendReplace the most recent commit with a new one.
--no-verifySkip pre-commit and commit-msg hooks.
-S, --gpg-signGPG-sign the commit.
--allow-emptyAllow a commit with no changes.
--fixup=<commit>Create a fixup commit for use with autosquash rebase.
-v, --verboseShow the diff in the commit message editor.

Examples

git commit -m "Fix off-by-one error in pagination"
# Quick commit with a one-line message

git commit -am "Update README"
# Stage tracked changes and commit in one step

git commit --amend -m "Better message"
# Rewrite the most recent commit's message

git commit --fixup=abc123
# Create a fixup commit to be squashed during rebase

Common Mistakes

Amending a published commit and then force-pushing rewrites history that others may have based work on, causing confusion. Only amend local, unshared commits. Another mistake is committing with -a when untracked files should also be included — -a ignores new files. Finally, never use --no-verify just to bypass failing tests; fix the test or the code instead.

Related Commands

git add, git status, git log, git revert