Open Source Guide
Tutorials

Commit Changes

Learn how to commit your changes with good commit messages

Commit Changes

Committing saves your changes to your local Git history with a descriptive message.

What is a Commit?

A commit is like a snapshot of your project at a specific point in time. It includes:

  • The changes you made
  • A message describing the changes
  • Author information
  • Timestamp

Step-by-Step Guide

Step 1: Check Your Changes

# See what files you changed
git status

# See the actual changes
git diff

Step 2: Stage Your Changes

# Stage specific files
git add filename.txt

# Stage all changes
git add .

# Stage multiple specific files
git add file1.txt file2.txt file3.txt

Step 3: Commit Your Changes

# Commit with a message
git commit -m "Fix typo in README.md"

# For longer messages, use an editor
git commit

Writing Good Commit Messages

The Format

Type: Brief description (50 chars or less)

More detailed explanation if needed (wrap at 72 chars).
Explain what and why, not how.

- Bullet points are okay
- Use present tense: "Add feature" not "Added feature"
- Reference issues: "Fixes #123"

Commit Types

  • Fix: - Bug fixes
  • Add: - New features
  • Update: - Updates to existing features
  • Remove: - Removing code or files
  • Refactor: - Code refactoring
  • Docs: - Documentation changes
  • Style: - Formatting, missing semicolons, etc.
  • Test: - Adding tests
  • Chore: - Maintenance tasks

Good Examples ✅

git commit -m "Fix: Correct broken link in footer"
git commit -m "Add: Dark mode toggle button"
git commit -m "Update: Improve error handling in API"
git commit -m "Docs: Add installation instructions"

Bad Examples ❌

git commit -m "fix"
git commit -m "updates"
git commit -m "changed stuff"
git commit -m "asdfasdf"

Verify Your Commit

# See your commit history
git log

# See the last commit
git log -1

# See commits with changes
git log -p

# See a prettier log
git log --oneline --graph

Amending Commits

Made a mistake? You can fix your last commit:

# Change the commit message
git commit --amend -m "New message"

# Add forgotten files
git add forgotten-file.txt
git commit --amend --no-edit

Only amend commits that haven't been pushed yet!


Next Steps

Your changes are now committed! Time to push them to GitHub. 💾

Your Progress

0/12
0%