Skip to main content
Back to command reference
Working with Changes

git commit

Record staged changes as a permanent snapshot in history

Practical example

bash
git add .
git commit -m "Fix login validation error"
# Creates commit abc1234 with author, date, and message

Command overview & how it works

Takes all currently staged changes and creates a permanent snapshot with a unique SHA-1 hash, author metadata, timestamp, and commit message. A well-written commit message follows the conventional format: a short summary line (50 chars or fewer), a blank line, then a longer body explaining what and why. Use git commit -m "message" for a quick inline message, or just git commit to open your configured editor for a detailed message. Use git commit --amend to modify the most recent commit (message, content, or both) — useful for fixing typos or forgetting to stage a file. Use git commit -a to automatically stage all tracked files before committing, bypassing the separate git add step. Every commit is immutable — once created, its history should not be rewritten on shared branches.

Chapter 01 · Mental Model & Architecture

Get the complete offline Git Field Guide

The 97-page PDF + ePub course — ₹499. Read this command, offline.

Learn more

Practical tips

  • Keep the subject line under 50 characters and use the imperative mood: 'Fix bug', not 'Fixed bug'.
  • Use git commit --amend to fix the message or add a forgotten file to your most recent commit — before pushing it.
  • Write a body after a blank line explaining the 'why'; the diff already shows the 'what'.

Deep-dive guides & tutorials

In-depth walkthroughs and practical scenarios related to git commit

All guides →
  • Guide

    How to Install Git on Windows, macOS, and Linux

    A step-by-step setup guide covering every major platform, from Homebrew and Winget to package managers, plus verifying your install and configuring your identity.

    7 min readRead guide
  • Tutorial

    Git Basics Every Developer Should Know

    Understand the core concepts — repositories, commits, branches, and remotes — before diving into the command line.

    6 min readRead guide
  • Guide

    How to Write Better Git Commit Messages

    A practical guide to writing clear, conventional commit messages that make your project history readable and your team more productive.

    6 min readRead guide

Related commands

More from Working with Changes