Getting Started Git Basics Commit

Commit

Understand what a Git commit contains, how it relates to the staging area, and when it becomes shared.

A commit is a saved snapshot of the staged changes in a repository, along with a message describing that change.

Commits are the basic building blocks of Git history. Each commit records a new point in the history of the project.

What a commit contains

A commit usually includes:

  • The snapshot Git is saving for the repository at that point.
  • A commit message written by the author.
  • Metadata such as the author, time, and parent commit.
  • A unique identifier called a commit hash.

Although people often think of a commit as "the changed lines," Git also treats it as a saved project state built from the staged content.

Commits come from the staging area

Git creates a commit from what is currently in the staging area, not from every change in the worktree.

That means:

  • Staged changes go into the commit.
  • Unstaged changes do not.
  • You can keep worktree edits local while committing only the part that is ready.

This is why checking the staged state before committing is so important.

Why commit messages matter

A good commit message helps other people, and your future self, understand why a change was made.

The message does not need to be long, but it should describe the purpose of the commit clearly enough that someone reading history can follow what happened.

Good commit messages make it easier to:

  • Review project history later.
  • Understand when and why a behavior changed.
  • Find the commit that introduced or fixed something.

Local commits vs pushed commits

One important Git idea is that making a commit is not the same thing as sharing it.

When you create a commit, it is first saved only in your local repository.

It becomes visible to collaborators only after you push it to a shared remote repository.

This separation is useful because you can:

  • Make commits locally while still refining your work.
  • Review or reorganize local history before sharing it.
  • Work without a network connection and push later.

Commit history

Each commit points back to one or more earlier commits, which is how Git builds the history of a project.

As you add commits, your current branch moves forward to the newest one. That is why commits, history, and branches are so closely connected.

Documentation

Search

move open Esc close

Browse the docs or start typing to filter results.