What is git commit?

The git commit command captures a snapshot of the currently staged changes in your repository.

Basic Syntax

git commit -m "your commit message"

This creates a new commit with a message describing the change.

Example

git add index.html
git commit -m "Add homepage content"

Skip Staging and Commit Directly

git commit -a -m "Updated files"

This stages and commits tracked file changes in one step.

Amend Last Commit

git commit --amend -m "New commit message"

This replaces the previous commit with a new one.

Push to GitHub

git push origin main

After committing locally, use this to upload to GitHub.