← Back to all tutorials

Making Your First Commits

Learn about Making Your First Commits

A commit is a snapshot of your project at a specific point in time. It records exactly which files changed, what changed, who made the change, and when. Think of each commit as a save point — you can always go back to any commit in your project's history.

Making Your First Commit

# Create some files
echo "# My Project" > README.md
echo "console.log('Hello');" > app.js

# Stage the files
git add .

# Commit with a message
git commit -m "Initial commit: add README and app.js"

Output:

[main (root-commit) a1b2c3d] Initial commit: add README and app.js
 2 files changed, 2 insertions(+)
 create mode 100644 README.md
 create mode 100644 app.js

Anatomy of a Commit

Every commit stores:

  • SHA hash — A unique 40-character identifier (e.g., a1b2c3d4e5f6...). You usually only need the first 7 characters.
  • Author — Name and email from your git config
  • Timestamp — When the commit was made
  • Message — Your description of what changed
  • Parent — Reference to the previous commit (builds the history chain)
  • Snapshot — The state of all tracked files at that moment

Writing Good Commit Messages

# Good — specific and clear
git commit -m "Fix login form not validating empty email"
git commit -m "Add user profile photo upload"
git commit -m "Remove deprecated payment API"
git commit -m "Update dependencies to fix security vulnerability"

# Bad — vague and unhelpful
git commit -m "fix stuff"
git commit -m "updates"
git commit -m "WIP"
git commit -m "asdfasdf"

A good commit message answers: "If I apply this commit, it will..." followed by your message. For example: "If I apply this commit, it will fix login form not validating empty email."

Multi-Line Commit Messages

# Option 1: Open your editor
git commit
# This opens your configured editor for a longer message

# Option 2: Multiple -m flags
git commit -m "Add user authentication" -m "Implemented JWT-based auth with refresh tokens. Added login, register, and logout endpoints."

Shortcut: Stage + Commit

# Stage ALL tracked files and commit in one step
git commit -am "Update navigation styles"

# Note: This only works for files Git already knows about.
# New (untracked) files still need 'git add' first.

Amending Commits

# Oops, forgot to add a file to the last commit
git add forgotten-file.js
git commit --amend --no-edit    # Add to last commit, keep same message

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

# Warning: Only amend commits that haven't been pushed yet!

Viewing Your Commits

# View commit history
git log

# Compact view
git log --oneline

# See what changed in each commit
git log -p

# Show last 3 commits
git log -3

What's Next

You're now making commits. In the next episode, we'll learn how to delete and un-track files properly in Git.