Git Commit (original) (raw)

Last Updated : 27 Feb, 2026

git commit saves a snapshot of staged changes into the Git repository, creating a point in history that helps track and manage project progress.

Ways to Use the git commit Command

Ways to Use the git commit Command explains the different methods and options available for creating commits in Git.

1. Commit with a Message

git commit -m "Initial commit"

2. Commit All Changes at Once

git commit -a -m "Update all tracked files"

Automatically stages modified and deleted tracked files before committing.

**Note: Does not include untracked files-you still need git add for those.

3. Amend Last Commit

git commit --amend -m "Updated commit message"

4. Commit Interactively

git commit -p

git commit

Common Options for git commit

Option Description
-m Add a commit message inline
-a Automatically stage modified and deleted tracked files
--amend Modify the last commit
-p Commit interactively by hunk
--dry-run Show what would be committed without actually committing

Working with Git Commit

Working with Git Commit explains how commits are created, customized, viewed, amended, and managed in a Git workflow.

1. Understanding Commits and HEAD

2. Git Commit Flags

**Git provides several flags to customize commits:

3. Handling Modifications After a Commit

4. Amending a Commit

To fix the last commit without adding a new history:

git commit --amend -m "new message"