Skip to main content

How to Commit in Git (with git commit)

Short answer

The git commit command saves staged changes as a new snapshot in the local repository. Before committing, use git add to stage the files you want to include — only staged changes are wrapped into the commit. Run git commit -m "your message" to create the commit with an inline message. To include all currently changed tracked files without a separate git add step, use git commit -a -m "message". To fix a mistake in the most recent commit — wrong message or a forgotten change — use git commit --amend, which rewrites the last commit with any newly staged changes and/or a new message. Note that git commit only saves to the local repository; use git push to share commits with a remote.

A commit saves a snapshot of your staged changes to the local Git repository. Note two important things: first, you must explicitly stage changes with git add before committing — modified files are not included automatically. Second, a commit only saves to the local repository; you need git push to share it with a remote.

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Free. We email you a ZIP with our cheat sheets.


Basic Commit

Stage the files you want to include, then commit with a message:

git add index.html css/styles.css
git commit -m "Change titles and styling on homepage"

Commit All Changed Files

To include all currently changed tracked files without a separate git add step, use -a. Note that new untracked files are still not included:

git commit -a -m "Change titles and styling on homepage"

Amending the Last Commit

Use --amend to fix a mistake in the most recent commit — either the message, the staged content, or both. Git rewrites the last commit with the new changes:

git add forgotten-change.js
git commit --amend -m "New commit message"

Only amend commits that have not been pushed to a remote yet. Rewriting published commits causes problems for anyone who has already pulled them.


No Command Line Needed

Easy Committing in Tower

In case you are using the Tower Git client, committing is very easy: just check the changed files you want to include and enter your commit message. You can even add individual chunks and lines from a file instead of the whole file!

Free download

Download the Cheat Sheet

Get 18 of our most popular Cheat Sheets in one handy ZIP!