---
title: How to Commit Changes in Git
url: https://docs.vultr.com/how-to-commit-changes-in-git
description: Learn the essential steps to commit changes in Git, including staging files, writing meaningful commit messages, and best practices for effective version control.
publish_date: 2025-05-29T13:17:41.591156Z
last_updated: 2025-05-29T13:17:41.591156Z
author: Adarsh Sojitra
header_image: https://docs.vultr.com/public/doc-assets/2227/56addff0-be55-4b0d-a443-5e94bfc5cc46.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Committing changes is one of the most important actions in Git. It records the current state of your project by saving staged changes along with a message that explains what was done and why. Whether you're fixing a typo, adding a feature, or cleaning up old code, well-structured commits help you track progress, collaborate with others, and maintain a clean version history. This article covers basic commits, skipping the staging step, and amending previous commits.

## The Short Answer Version

```

# Stage all modified files
$ git add .

# Commit with a message
$ git commit -m "Describe what this commit does"

# Commit changes to tracked files without staging
$ git commit -a -m "Skip staging and commit modified files"

# Update the most recent commit message
$ git commit --amend -m "New commit message"
```

## Common Options for Committing Changes

| Command                            | Description                                                   |
|------------------------------------|---------------------------------------------------------------|
| `git add <file>`                  | Stages a specific file for the next commit                    |
| `git add .`                       | Stages all modified and new files in the current directory    |
| `git commit -m "message"`         | Commits all staged changes with a commit message              |
| `git commit -a -m "message"`      | Commits all modified **tracked** files without staging        |
| `git commit --amend`             | Updates the most recent commit with new changes or message    |

## Git Commit Without Staging

The `-a` flag lets you commit all modified **tracked** files directly without staging them first. This is useful when you want to skip `git add` but still commit file changes.

### Command Syntax

```
git commit -a -m "Your commit message"
```

* `-a`: Automatically stages all modified tracked files.
* `-m`: Attaches a commit message directly in the command.

### Command Demonstration

1. Create a tracked file under Git.

    ```console
    $ echo "Hello" > demo.txt
    ```

1. Stage the file.

    ```console
    $ git add demo.txt
    ```

1. Make an initial commit.

    ```console
    $ git commit -m "Initial commit"
    ```

1. Modify the file without staging.

    ```console
    $ echo "Appended second line to demo.txt" >> demo.txt
    ```

1. Commit the changes directly using `-a`.

    ```console
    $ git commit -a -m "Added second line to demo.txt"
    ```

1. Check your commit history.

    ```console
    $ git log --oneline
    ```

This workflow skips `git add` but only works on tracked files. Any **new** files still require staging before committing.

## Update or Amend a Git Commit

You can use the `--amend` flag with `git commit` to modify your most recent commit. This is helpful for adding missing changes, fixing typos in messages, or cleaning up your commit history before pushing.

### Command Syntax

```
git commit --amend
```

* `--amend`: Replaces the previous commit with a new one. This can modify the commit message, content, or both.
* `-m`: (Optional) Use this to supply a new message inline instead of opening your editor.

### Command Demonstration

#### Example 1: Add a forgotten file to the last commit

1. Stage the missing file.

    ```console
    $ git add file2.txt
    ```

1. Amend the last commit.

    ```console
    $ git commit --amend
    ```

    This opens your text editor to update the message (or keep it unchanged).

#### Example 2: Change the commit message without changing content

```console
$ git commit --amend -m "Updated commit message"
```

This rewrites the most recent commit message without modifying the files.

> [!WARNING]
> Avoid amending commits that have already been pushed to a remote repository shared with others. It rewrites history and may cause conflicts for your collaborators.

## Conclusion

In this article, you learned how to commit changes in Git effectively. You explored the core concepts of staging files, creating commits, skipping the staging step with `-a`, and updating the most recent commit using `--amend`. These workflows help maintain a clean, organized history and improve team collaboration.

With these techniques, you're now equipped to write clear commit messages, streamline your Git workflow, and maintain a version history that's easy to navigate and collaborate on.
