Git commit explained simply
The commit is the most fundamental operation in Git. Understand what it does, how to use it correctly, and what the best practices are for clear messages.
What is a Git commit?
A commit is a snapshot of your project at a given point in time. It's like a smart save: Git records the exact state of all files you added to the staging area.
Each commit contains: the changes made, a descriptive message, the author's name, the date, and a reference to the previous commit (the parent). This chain of commits forms your project's history.
Unlike a simple Ctrl+S, a commit is permanent and shareable. Once committed, your work is protected: even if you break everything afterward, you can always go back to that state.
How to make a commit
A commit always involves two steps. First, you add modified files to the staging area with git add. Then, you record them with git commit.
The -m flag lets you specify the message directly on the command line. Without it, Git will open your default text editor.
Most commonly used commit options
-m "message"Specify the commit message directly on the command line.
-aAutomatically stage all modified tracked files. Does not include new files.
--amendReplace the last commit. Useful to fix a message or add a forgotten file.
--no-editUsed with --amend to keep the previous commit message unchanged.
Commit message best practices
A good commit message explains why a change was made, not just what. Here are the most widely used conventions in the industry.
Good examples
feat: add contact formfix: correct cart total calculationstyle: refactor sidebar CSSdocs: add installation instructionstest: add User unit tests
Bad examples
fixToo vague, fix what?updateUpdate what?wipWork in progress is not a commitasdfghNo message = no useful historychanged everythingCatch-all commit impossible to review
The Conventional Commits convention
The most widespread convention in the industry follows the format: type: short description
feat: new featurefix: bug fixdocs: documentationstyle: formatting, CSSrefactor: refactoringtest: adding testschore: technical tasksci: continuous integrationView the commit history
The git log command displays the list of all commits. The --oneline option condenses each commit to a single line for a quick overview.
A clean history with clear messages and atomic commits is a sign of professionalism. It also makes debugging and collaboration much easier.
Common mistakes with git commit
Forgetting to run git add first
If you run git commit without staging any files, Git will tell you "nothing to commit". Don't forget the git add step.
Committing sensitive files
.env files, API keys, passwords: once committed, they stay in the history even after deletion. Use .gitignore before your first commit.
Making a massive commit
A commit that touches 50 files and mixes 3 topics is impossible to review and undo cleanly. Prefer atomic commits: one topic = one commit.
Using --amend on an already pushed commit
Amending a commit that is already on the remote will create conflicts for the entire team. Use git revert instead.
Part of the Git Basics guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions fréquentes
Ready to master git commit?
Practice commits in realistic scenarios with GitQuest investigations. It's free.
Get started now