Data report"State of code review 2024" is now liveRead the full report

How to use the git commit -m command

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


The git commit -m command saves changes to your local repository with a message describing the modifications. This guide provides an in-depth explanation of how to use git commit -m and its variations to efficiently manage changes in your codebase.

The git commit command captures a snapshot of the staged changes in your project. This snapshot is then stored in your local repository, which allows you to track the history of your project over time. The -m flag is used to provide a commit message directly from the command line without opening a text editor.

The basic syntax of the git commit -m command is:

Terminal
git commit -m "Your commit message here"

The message should be concise and explain what changes the commit introduces to the repository. Good commit messages are crucial for maintaining a readable and navigable history.

For more information on these messages see best practices for writing commit messages.

  1. Stage your changes: Before you can commit, you need to stage the changes you want to include in the commit. You can do this using the git add command:

    Terminal
    git add <file1> <file2>
  2. Commit the changes: Once your changes are staged, use the git commit -m command to commit them:

    Terminal
    git commit -m "feat(web-app): add login functionality to the app"
  3. View the commit: You can view the commit you just made using the git log command:

    Terminal
    git log --oneline

This will show a list of recent commits along with their commit messages.

The git commit -a -m command (or git commit -am) is a shortcut that allows you to skip the staging step (using git add) for modified files (it does not affect new or deleted files). It stages changes to modified files and commits them in one step:

Terminal
git commit -a -m "Update existing files with bug fixes"

This command is particularly useful when you have made changes to existing files and want to quickly commit those changes without individually staging each one.

The git commit -m command helps you cleanly organize and manage changes to your projects. By understanding how to use this command, along with best practices for commit messages, you can enhance your productivity and maintain a clear history of your project.

Git gud
"It's the first Git workflow I've used that actually feels good."
–@robboclancy
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2