The git commit command

The git commit command is used to save your changes in a Git repository. When you commit, you’re creating a “snapshot” of the current state of your project.

Here’s a breakdown of how it works:

  1. Make Changes

Before committing, you make changes to your files—add, modify, or delete content.

  1. Stage Changes

After making changes, you use the git add command to stage the files you want to include in the next commit. Staging means telling Git, “Hey, these are the changes I want to save.”

git add <file1> <file2> ...

Alternatively, you can use git add -A to stage all changes.

  1. Commit Changes

Once you’ve staged the changes, you use the git commit command:

git commit -m "Your commit message here"

The -m flag allows you to add a short message describing what changes you made. This message helps you and others understand the purpose of the commit.

  1. Create Snapshot

Git creates a snapshot of the staged changes, along with your commit message, and stores it in the version history.

So, in essence, git commit is like taking a picture of your project at a specific point in time, making it easy to track the evolution of your code over the course of development.

Command options