How to Commit in Git (with git commit)
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!
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.
Tip
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!
Get our popular Git Cheat Sheet for free!
You'll find the most important commands on the front and helpful best practice tips on the back. Over 100,000 developers have downloaded it to make Git a little bit easier.
About Us
As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.
Just like with Tower, our mission with this platform is to help people become better professionals.
That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.