Header

Committing file changes

How to save changes to files using Git.

What are commits?

Git’s main power comes from the ability to keep a record of every single change made to the files in your project by taking snapshots called commits.

When you commit, Git only stores a summary of the changes, rather than storing entire copies of every changed file. This keeps things fast and stops a repository from getting unreasonably large.

Adding changes to the staging area

Before you commit, you need to make some changes in your project.

You can run the git status command at any time for a list of files that have been added, changed, or removed inside your working directory.

The output will look a little something like this:

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    index.html

nothing added to commit but untracked files present (use "git add" to track)

Every change you make isn’t automatically included when you commit. You'll manually need to tell Git which changes you want to be included by adding them to the staging area using the git add command.

For example, let’s say you've made changes to index.html. To add all the changes in this file, you can simply type git add index.html.

If you run git status again, you’ll see that the output has changed slightly:

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   index.html

Don’t worry, you don’t need to add every file one-by-one!

You can enter the name of an entire folder, or you just can use git add -A to add all of the changed files to the staging area at once.

Creating your first commit

Once you've added all the files you want to include in the commit, you'll need to run the following command:

git commit -m "message"

Replace message with a brief summary of the changes that you've made. Once you press enter the commit will be created.

[master (root-commit) d240853] Create the home page
 1 file changed, 107 insertions(+)
 create mode 100644 index.html

Want to learn more about Git?

This tutorial is part of a free beginner-friendly course!

Learn More

Proudly powered by Katapult. Running on 100% renewable energy.